List of usage examples for org.jfree.chart JFreeChart JFreeChart
public JFreeChart(Plot plot)
From source file:net.sourceforge.entrainer.jfreechart.UnitChart.java
private void init() { chart = new JFreeChart(getXYPlot()); chartPanel = new ChartPanel(chart); chartPanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(ChartMouseEvent event) { }/*from w w w . j a va 2s. co m*/ public void chartMouseMoved(ChartMouseEvent event) { if (event.getEntity() != null && (currentEntity == null || !currentEntity.equals(event.getEntity()))) { if (event.getEntity() instanceof XYItemEntity) { showPopup((XYItemEntity) event.getEntity()); } } else if (event.getEntity() == null && timer != null) { timer.dismiss(); timer = null; currentEntity = null; } } }); getContentPane().add(chartPanel); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.isControlDown() && e.getClickCount() == 1) { openBrowser(getLocalDocAddress()); } } }); }
From source file:com.bdb.weather.display.current.Thermometer.java
private ChartViewer createChartElements() { thermometerPlot// www . java 2 s.c o m .setMercuryPaint(new GradientPaint(0.0f, 0.0f, Color.RED.darker(), 5.0f, 5.0f, Color.RED, true)); thermometerPlot.setUseSubrangePaint(false); thermometerPlot.setBulbRadius(15); thermometerPlot.setColumnRadius(10); thermometerPlot.setValueLocation(ThermometerPlot.RIGHT); thermometerPlot.setValuePaint(Color.BLACK); thermometerPlot.setSubrange(0, 80.0, 80.0); thermometerPlot.setSubrangePaint(0, Color.BLUE); thermometerPlot.setSubrangePaint(1, Color.RED); thermometerPlot.setSubrange(1, 1000.0, 1000.0); thermometerPlot.setSubrange(2, 1000.0, 1000.0); thermometerPlot.setBackgroundPaint(Color.GRAY); thermometerPlot.setOutlineVisible(false); thermometerPlot.setValueFont(thermometerPlot.getValueFont().deriveFont(14.0F).deriveFont(Font.PLAIN)); chart = new JFreeChart(thermometerPlot); chart.setTitle(titleProperty.getValue()); chart.setBackgroundPaint(Color.GRAY); ChartViewer chartViewer = new ChartViewer(chart); chartViewer.setMinHeight(75); chartViewer.setMinWidth(25); return chartViewer; }
From source file:it.alus.GPSreceiver.instruments.Altimeter.java
public Altimeter(float groundAltitudeFt) { super(null);/*from ww w. j a v a 2 s. c o m*/ altitude = 0; if (groundAltitudeFt < 0) groundAltitude = 0; else groundAltitude = groundAltitudeFt; hoursDataset = new DefaultValueDataset(0.0); minutesDataset = new DefaultValueDataset(0.0); DialPlot plot = new DialPlot(); plot.setView(0.0, 0.0, 1.0, 1.0); Image background = Toolkit.getDefaultToolkit().getImage(getClass().getResource("altimeter.png")); plot.setDataset(0, hoursDataset); plot.setDataset(1, minutesDataset); StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setBackgroundPaint(Color.lightGray); dialFrame.setForegroundPaint(Color.gray); DialTextAnnotation annotation = new DialTextAnnotation("Feet"); annotation.setFont(new Font("Arial", 1, 14)); annotation.setRadius(0.4D); annotation.setPaint(Color.lightGray); plot.addLayer(annotation); DialValueIndicator valueindicator = new DialValueIndicator(0); NumberFormat formatter = new DecimalFormat("#"); plot.addLayer(valueindicator); plot.setDialFrame(dialFrame); StandardDialScale scale = new StandardDialScale(0, 10, 90, -360, 1, 10); scale.setMajorTickPaint(Color.white); scale.setMinorTickPaint(Color.lightGray); scale.setFirstTickLabelVisible(false); scale.setTickRadius(0.88); scale.setTickLabelOffset(0.15); scale.setTickLabelFormatter(formatter); scale.setTickLabelFont(new Font("Arial", Font.BOLD, 24)); scale.setTickLabelPaint(Color.white); plot.addScale(3, scale); plot.setBackground(new DialBackground(Color.black)); StandardDialScale hourScale = new StandardDialScale(0, 10000, 90, -360, 1000, 10); hourScale.setVisible(false); hourScale.setTickRadius(0.88); hourScale.setTickLabelOffset(0.15); plot.addScale(0, hourScale); StandardDialScale minScale = new StandardDialScale(0, 1000, 90, -360, 0, 0); minScale.setVisible(false); minScale.setMajorTickIncrement(5.0); minScale.setTickRadius(0.68); plot.addScale(1, minScale); Pointer hourNeedle = new Pointer(0); hourNeedle.setRadius(0.55); hourNeedle.setFillPaint(Color.lightGray); plot.addLayer(hourNeedle); plot.mapDatasetToScale(1, 1); Pointer minNeedle = new Pointer(1); minNeedle.setFillPaint(Color.white); plot.addLayer(minNeedle); DialCap cap = new DialCap(); cap.setRadius(0.10); cap.setFillPaint(Color.lightGray); plot.setCap(cap); jChart = new JFreeChart(plot); jChart.setBackgroundImage(background); super.setChart(jChart); super.setPreferredSize(new Dimension(400, 400)); }
From source file:it.alus.GPSreceiver.instruments.Compass.java
public Compass(boolean trueTrack) { super(null);/*from w w w . j a v a2 s.com*/ isTrueTrack = trueTrack; dataset = new DefaultValueDataset(0.0); DialPlot plot = new DialPlot(); //Image background=Toolkit.getDefaultToolkit().getImage(getClass().getResource("heading.png")); //plot.setBackgroundImage(background); plot.setView(0.0, 0.0, 1.0, 1.0); plot.setDataset(0, dataset); StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setBackgroundPaint(Color.lightGray); dialFrame.setForegroundPaint(Color.gray); N = new DialTextAnnotation("N"); N.setFont(new Font("Arial", 1, 32)); N.setPaint(Color.white); N.setAnchor(TextAnchor.CENTER); plot.addLayer(N); S = new DialTextAnnotation("S"); S.setFont(new Font("Arial", 1, 32)); S.setPaint(Color.white); S.setAnchor(TextAnchor.CENTER); plot.addLayer(S); W = new DialTextAnnotation("W"); W.setFont(new Font("Arial", 1, 32)); W.setPaint(Color.white); W.setAnchor(TextAnchor.CENTER); plot.addLayer(W); E = new DialTextAnnotation("E"); E.setFont(new Font("Arial", 1, 32)); E.setPaint(Color.white); E.setAnchor(TextAnchor.CENTER); plot.addLayer(E); repositionDirectionsLabels(90); DialValueIndicator valueindicator = new DialValueIndicator(0); plot.addLayer(valueindicator); plot.setDialFrame(dialFrame); realScale = new StandardDialScale(0, 360, 90, -360, 30, 6); realScale.setVisible(false); realScale.setFirstTickLabelVisible(false); plot.addScale(0, realScale); dispScale = new StandardDialScale(0, 36, 90, -360, 3, 15); dispScale.setFirstTickLabelVisible(false); dispScale.setMajorTickPaint(Color.white); dispScale.setMinorTickPaint(Color.lightGray); dispScale.setFirstTickLabelVisible(true); dispScale.setTickRadius(0.88); dispScale.setTickLabelOffset(0.15); NumberFormat formatter = new DecimalFormat("#"); dispScale.setTickLabelFormatter(formatter); dispScale.setTickLabelFont(new Font("Arial", Font.BOLD, 22)); dispScale.setTickLabelPaint(Color.white); plot.addScale(1, dispScale); plot.setBackground(new DialBackground(Color.black)); Pointer needle = new Pointer(0); needle.setFillPaint(Color.red); needle.setRadius(0.8); plot.addLayer(needle); plot.mapDatasetToScale(1, 1); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.gray); plot.setCap(cap); jChart = new JFreeChart(plot); //jChart.setBackgroundImage(background); super.setChart(jChart); super.setPreferredSize(new Dimension(400, 400)); }
From source file:com.bdb.weather.display.current.Hygrometer.java
private ChartViewer createChartElements() { humidityPlot.addLayer(/*from w w w.jav a 2 s .co m*/ new DialBackground(new GradientPaint(0.0f, 0.0f, Color.LIGHT_GRAY, 100.0f, 0.0f, Color.blue))); StandardDialScale scale = new StandardDialScale(Humidity.MIN_HUMIDITY.get(), Humidity.MAX_HUMIDITY.get(), 240.0, -300.0, 10.0, 9); scale.setTickLabelFont(scale.getTickLabelFont().deriveFont(14.0F).deriveFont(Font.PLAIN)); scale.setTickRadius(.9); scale.setTickLabelFormatter(new DecimalFormat("#")); scale.setTickLabelOffset(.2); scale.setTickLabelPaint(Color.BLACK); humidityPlot.addScale(0, scale); humidityPlot.setDialFrame(new StandardDialFrame()); DialValueIndicator valueInd = new DialValueIndicator(0); valueInd.setNumberFormat(new DecimalFormat("# '%rH'")); Color c = new Color(255, 255, 255, 0); valueInd.setBackgroundPaint(c); valueInd.setOutlinePaint(c); valueInd.setPaint(Color.cyan); humidityPlot.addLayer(valueInd); double angle = valueInd.getAngle(); double radius = valueInd.getRadius(); trendAnnotation.setPaint(Color.cyan); trendAnnotation.setAngle(angle); trendAnnotation.setRadius(radius + .1); humidityPlot.addLayer(trendAnnotation); DialPointer.Pointer pointer = new DialPointer.Pointer(0); humidityPlot.addPointer(pointer); DialCap cap = new DialCap(); cap.setRadius(cap.getRadius() * 1.5); humidityPlot.setCap(cap); range = new StandardDialRange(Humidity.MIN_HUMIDITY.get(), Humidity.MAX_HUMIDITY.get(), Color.BLACK); range.setInnerRadius(.40); range.setOuterRadius(.45); range.setScaleIndex(0); humidityPlot.addLayer(range); JFreeChart chart = new JFreeChart(humidityPlot); chart.setBackgroundPaint(Color.GRAY); ChartViewer chartViewer = new ChartViewer(chart); //chartViewer.setMinHeight(100); //chartViewer.setMinWidth(100); //chartViewer.setMaxHeight(400); //chartViewer.setMaxWidth(400); //chartViewer.setBackground(Color.GRAY); return chartViewer; }
From source file:com.xpn.xwiki.plugin.charts.ChartingPlugin.java
public Chart generateChart(ChartParams params, XWikiContext context) throws GenerateException { try {//w ww .j a va 2s. c o m // Obtain the corresponding data source and wrap it into a data source object DataSource dataSource = MainDataSourceFactory.getInstance().create(params.getMap(ChartParams.SOURCE), context); String type = params.getString(ChartParams.TYPE); Plot plot; try { String factoryClassName = ChartingPlugin.class.getPackage().getName() + ".plots." + Character.toUpperCase(type.charAt(0)) + type.toLowerCase().substring(1) + "PlotFactory"; Class factoryClass = Class.forName(factoryClassName); Method method = factoryClass.getMethod("getInstance", new Class[] {}); PlotFactory factory = (PlotFactory) method.invoke(null, new Object[] {}); plot = factory.create(dataSource, params); } catch (InvocationTargetException e) { throw new GenerateException(e.getTargetException()); } catch (Throwable e) { throw new GenerateException(e); } ChartCustomizer.customizePlot(plot, params); JFreeChart jfchart = new JFreeChart(plot); ChartCustomizer.customizeChart(jfchart, params); return generatePngChart(jfchart, params, context); } catch (IOException ioe) { throw new GenerateException(ioe); } catch (DataSourceException dse) { throw new GenerateException(dse); } }
From source file:jgnash.ui.report.compiled.SecurityHighLowChart.java
JPanel createPanel() { combo = new SecurityComboBox(); // create an empty chart for panel construction chartPanel = new ChartPanel(new JFreeChart(new XYPlot())); FormLayout layout = new FormLayout("p, 4dlu:g", ""); DefaultFormBuilder builder = new DefaultFormBuilder(layout); builder.append(combo);// w w w .j av a 2 s . co m builder.nextLine(); builder.appendRelatedComponentsGapRow(); builder.nextLine(); builder.appendRow(RowSpec.decode("fill:p:g")); builder.append(chartPanel, 2); combo.addActionListener(e -> updateChart()); return builder.getPanel(); }
From source file:org.fhaes.FHRecorder.GraphicsPanel.java
/** * Recalculates the charts based on the latest sample * data/*from w w w . ja va 2 s . co m*/ * @return */ private JFreeChart updateGraph() { try { NumberAxis rangeAxis = new NumberAxis(); XYBarRenderer renderer = new XYBarRenderer(); renderer.setSeriesPaint(0, Color.BLUE); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.configure(); numEventsDataset = new SlidingCategoryDataset(getNumEventsDataset(), 0, NUM_COLUMNS); BarRenderer numEventsRenderer = new BarRenderer(); numEventsRenderer.setSeriesPaint(0, Color.BLUE); plot = new CategoryPlot(numEventsDataset, new CategoryAxis("Event Years"), rangeAxis, numEventsRenderer); numSamplesDataset = new SlidingCategoryDataset(getNumSamplesDataset(), 0, NUM_COLUMNS); plot.setDataset(1, numSamplesDataset); LineAndShapeRenderer numSamplesRenderer = new LineAndShapeRenderer(); numSamplesRenderer.setSeriesPaint(0, Color.RED); plot.setRenderer(1, numSamplesRenderer); numRecordersDataset = new SlidingCategoryDataset(getNumRecordersDataset(), 0, NUM_COLUMNS); plot.setDataset(2, numRecordersDataset); LineAndShapeRenderer numRecordersRenderer = new LineAndShapeRenderer(); numRecordersRenderer.setSeriesPaint(0, Color.GREEN); plot.setRenderer(2, numRecordersRenderer); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); updateVisibleYears(savedPercent); return new JFreeChart(plot); } catch (IllegalArgumentException e) { // Something was wrong with the file } return null; }
From source file:net.relet.freimap.LinkInfo.java
public void setFlowProfile(LinkedList<FlowData> lp) { XYSeries packets = new XYSeries("packets"); XYSeries bytes = new XYSeries("bytes"); XYSeries icmp = new XYSeries("icmp"); XYSeries tcp = new XYSeries("tcp"); XYSeries udp = new XYSeries("udp"); XYSeries other = new XYSeries("other"); XYSeriesCollection data1 = new XYSeriesCollection(bytes); XYSeriesCollection data2 = new XYSeriesCollection(packets); XYSeriesCollection data3 = new XYSeriesCollection(icmp); data3.addSeries(tcp);//from w ww .ja v a2 s. c om data3.addSeries(udp); data3.addSeries(other); //linkChart = ChartFactory.createXYLineChart("packets, bytes\r\nicmp, tcp, udp other", "time", "count", data1, PlotOrientation.VERTICAL, false, false, false); ValueAxis domain = new DateAxis(); ValueAxis range1 = new NumberAxis(); ValueAxis range2 = new NumberAxis(); ValueAxis range3 = new NumberAxis(); CombinedDomainXYPlot plot = new CombinedDomainXYPlot(domain); plot.add(new XYPlot(data2, domain, range1, new XYLineAndShapeRenderer(true, false))); plot.add(new XYPlot(data1, domain, range2, new XYLineAndShapeRenderer(true, false))); plot.add(new XYPlot(data3, domain, range1, new XYLineAndShapeRenderer(true, false))); linkChart = new JFreeChart(plot); linkChart.setTitle(""); sexupLayout(linkChart); long min = lp.getFirst().begin, max = lp.getLast().end; for (float i = 0.0f; i < 1000.0f; i += 1.0f) { long cur = min + (long) ((max - min) * (i / 1000.0)); long cpackets = 0; long cbytes = 0; long cicmp = 0; long ctcp = 0; long cudp = 0; long cother = 0; Iterator<FlowData> li = lp.iterator(); while (li.hasNext()) { FlowData data = li.next(); if (data.begin > cur) break; if (data.end < cur) continue; cpackets += data.packets; cbytes += data.bytes; switch (data.protocol) { case 1: { cicmp += data.packets; break; } case 6: { ctcp += data.packets; break; } case 17: { cudp += data.packets; break; } default: { cother += data.packets; break; } } } packets.add(cur, cpackets); bytes.add(cur, cbytes); icmp.add(cur, cicmp); tcp.add(cur, ctcp); udp.add(cur, cudp); other.add(cur, cother); } status = STATUS_AVAILABLE; }
From source file:ch.algotrader.client.chart.ChartTab.java
public ChartTab(ChartPlugin chartPlugin) { super(new JFreeChart(new XYPlot()), true, true, true, true, true); this.chartPlugin = chartPlugin; initPopupMenu();// ww w . ja va 2 s . c om }