1 40 41 package org.jfree.chart.demo; 42 43 import org.jfree.chart.ChartFactory; 44 import org.jfree.chart.ChartPanel; 45 import org.jfree.chart.JFreeChart; 46 import org.jfree.chart.axis.DateAxis; 47 import org.jfree.chart.plot.PlotOrientation; 48 import org.jfree.chart.plot.XYPlot; 49 import org.jfree.chart.renderer.ClusteredXYBarRenderer; 50 import org.jfree.data.IntervalXYDataset; 51 import org.jfree.data.time.Day; 52 import org.jfree.data.time.TimeSeries; 53 import org.jfree.data.time.TimeSeriesCollection; 54 import org.jfree.ui.ApplicationFrame; 55 import org.jfree.ui.RefineryUtilities; 56 57 62 public class XYBarChartDemo2 extends ApplicationFrame { 63 64 69 public XYBarChartDemo2(String title) { 70 71 super(title); 72 73 TimeSeries series1 = new TimeSeries("Series 1", Day.class); 75 series1.add(new Day(1, 1, 2003), 54.3); 76 series1.add(new Day(2, 1, 2003), 20.3); 77 series1.add(new Day(3, 1, 2003), 43.4); 78 series1.add(new Day(4, 1, 2003), -12.0); 79 80 TimeSeries series2 = new TimeSeries("Series 2", Day.class); 81 series2.add(new Day(1, 1, 2003), 8.0); 82 series2.add(new Day(2, 1, 2003), 16.0); 83 series2.add(new Day(3, 1, 2003), 21.0); 84 series2.add(new Day(4, 1, 2003), 5.0); 85 86 TimeSeriesCollection data = new TimeSeriesCollection(); 87 data.setDomainIsPointsInTime(false); 88 data.addSeries(series1); 89 data.addSeries(series2); 90 91 JFreeChart chart = createChart(data); 92 93 ChartPanel chartPanel = new ChartPanel(chart); 95 chartPanel.setPreferredSize(new java.awt.Dimension (500, 300)); 96 setContentPane(chartPanel); 97 98 } 99 100 111 118 private JFreeChart createChart(IntervalXYDataset dataset) { 119 JFreeChart chart = ChartFactory.createXYBarChart( 120 "XY Bar Chart Demo 2", "X", "Y", dataset, PlotOrientation.HORIZONTAL, 125 true, true, 127 false 128 ); 129 130 XYPlot plot = chart.getXYPlot(); 132 plot.setDomainAxis(new DateAxis("Date")); 133 plot.setRenderer(new ClusteredXYBarRenderer()); 134 return chart; 136 } 137 138 143 public static void main(String [] args) { 144 145 XYBarChartDemo2 demo = new XYBarChartDemo2("XY Bar Chart Demo 2"); 146 demo.pack(); 147 RefineryUtilities.centerFrameOnScreen(demo); 148 demo.setVisible(true); 149 150 } 151 152 } 153 | Popular Tags |