1 40 41 package org.jfree.chart.demo; 42 43 import java.awt.Color ; 44 import java.awt.GradientPaint ; 45 46 import org.jfree.chart.ChartFactory; 47 import org.jfree.chart.ChartPanel; 48 import org.jfree.chart.JFreeChart; 49 import org.jfree.chart.axis.DateAxis; 50 import org.jfree.chart.axis.DateTickMarkPosition; 51 import org.jfree.chart.labels.TimeSeriesToolTipGenerator; 52 import org.jfree.chart.plot.PlotOrientation; 53 import org.jfree.chart.plot.XYPlot; 54 import org.jfree.chart.renderer.XYItemRenderer; 55 import org.jfree.data.time.TimeSeriesCollection; 56 import org.jfree.ui.ApplicationFrame; 57 import org.jfree.ui.RefineryUtilities; 58 59 64 public class XYBarChartDemo extends ApplicationFrame { 65 66 71 public XYBarChartDemo(String title) { 72 73 super(title); 74 75 TimeSeriesCollection data = DemoDatasetFactory.createTimeSeriesCollection1(); 76 data.setDomainIsPointsInTime(false); 77 JFreeChart chart = ChartFactory.createXYBarChart( 78 title, 79 "X", 80 "Y", 81 data, 82 PlotOrientation.VERTICAL, 83 true, 84 false, 85 false 86 ); 87 88 chart.setBackgroundPaint(new GradientPaint (0, 0, Color.white, 1000, 0, Color.blue)); 90 91 XYItemRenderer renderer = chart.getXYPlot().getRenderer(); 92 renderer.setToolTipGenerator(new TimeSeriesToolTipGenerator()); 93 94 XYPlot plot = chart.getXYPlot(); 95 DateAxis axis = (DateAxis) plot.getDomainAxis(); 96 axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); 97 98 ChartPanel chartPanel = new ChartPanel(chart); 100 chartPanel.setPreferredSize(new java.awt.Dimension (500, 300)); 101 setContentPane(chartPanel); 102 103 } 104 105 116 121 public static void main(String [] args) { 122 123 XYBarChartDemo demo = new XYBarChartDemo("XY Bar Chart Demo"); 124 demo.pack(); 125 RefineryUtilities.centerFrameOnScreen(demo); 126 demo.setVisible(true); 127 128 } 129 130 } 131 | Popular Tags |