private static JFreeChart createChart() { DateAxis dateaxis = new DateAxis("Date"); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); NumberAxis numberaxis = new NumberAxis("Value"); IntervalXYDataset intervalxydataset = createDataset1(); XYBarRenderer xybarrenderer = new XYBarRenderer(0.20000000000000001D); xybarrenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator( "{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); XYPlot xyplot = new XYPlot(intervalxydataset, dateaxis, numberaxis, xybarrenderer); NumberAxis numberaxis1 = new NumberAxis("Value 2"); xyplot.setRangeAxis(1, numberaxis1); XYDataset xydataset = createDataset2A(); StandardXYItemRenderer standardxyitemrenderer = new StandardXYItemRenderer(); standardxyitemrenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator( "{0}: ({1}, {2})", new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); xyplot.setDataset(1, xydataset); xyplot.setRenderer(1, standardxyitemrenderer); XYDataset xydataset1 = createDataset2B(); xyplot.setDataset(2, xydataset1); xyplot.setRenderer(2, new StandardXYItemRenderer()); xyplot.mapDatasetToRangeAxis(2, 1); xyplot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); xyplot.setOrientation(PlotOrientation.VERTICAL); JFreeChart jfreechart = new JFreeChart("Overlaid XYPlot Demo 2", JFreeChart.DEFAULT_TITLE_FONT, xyplot, true); ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
public MyDemoPanel() { super(new BorderLayout()); lastValue = new double[3]; CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time")); datasets = new TimeSeriesCollection[3]; for (int i = 0; i < 3; i++) { lastValue[i] = 100D; TimeSeries timeseries = new TimeSeries("Random " + i); datasets[i] = new TimeSeriesCollection(timeseries); NumberAxis numberaxis = new NumberAxis("Y" + i); numberaxis.setAutoRangeIncludesZero(false); XYPlot xyplot = new XYPlot(datasets[i], null, numberaxis, new StandardXYItemRenderer()); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.add(xyplot); } JFreeChart jfreechart = new JFreeChart("Dynamic Data Demo 3", combineddomainxyplot); addChart(jfreechart); LegendTitle legendtitle = (LegendTitle) jfreechart.getSubtitle(0); legendtitle.setPosition(RectangleEdge.RIGHT); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart.setBorderPaint(Color.black); jfreechart.setBorderVisible(true); ValueAxis valueaxis = combineddomainxyplot.getDomainAxis(); valueaxis.setAutoRange(true); valueaxis.setFixedAutoRange(20000D); ChartUtilities.applyCurrentTheme(jfreechart); ChartPanel chartpanel = new ChartPanel(jfreechart); add(chartpanel); JPanel jpanel = new JPanel(new FlowLayout()); for (int j = 0; j < 3; j++) { JButton jbutton1 = new JButton("Series " + j); jbutton1.setActionCommand("ADD_DATA_" + j); jbutton1.addActionListener(this); jpanel.add(jbutton1); } JButton jbutton = new JButton("ALL"); jbutton.setActionCommand("ADD_ALL"); jbutton.addActionListener(this); jpanel.add(jbutton); add(jpanel, "South"); chartpanel.setPreferredSize(new Dimension(500, 470)); chartpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }