1 37 38 package org.jfree.chart.demo; 39 40 import org.jfree.chart.ChartPanel; 41 import org.jfree.chart.JFreeChart; 42 import org.jfree.chart.axis.NumberAxis; 43 import org.jfree.chart.axis.SymbolicAxis; 44 import org.jfree.chart.axis.ValueAxis; 45 import org.jfree.chart.labels.SymbolicXYToolTipGenerator; 46 import org.jfree.chart.plot.XYPlot; 47 import org.jfree.chart.renderer.StandardXYItemRenderer; 48 import org.jfree.chart.renderer.XYItemRenderer; 49 import org.jfree.data.XYDataset; 50 import org.jfree.data.YisSymbolic; 51 import org.jfree.ui.ApplicationFrame; 52 import org.jfree.ui.RefineryUtilities; 53 54 59 public class SymbolicChartDemo1 extends ApplicationFrame { 60 61 66 public SymbolicChartDemo1(String title) { 67 68 super(title); 69 70 XYDataset dataset = createDataset(); 72 73 ValueAxis domainAxis = new NumberAxis("X"); 74 SymbolicAxis symbolicAxis 75 = new SymbolicAxis("Y", ((YisSymbolic) dataset).getYSymbolicValues()); 76 77 XYPlot plot = new XYPlot(dataset, domainAxis, symbolicAxis, null); 78 XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, 79 new SymbolicXYToolTipGenerator()); 80 plot.setRenderer(renderer); 81 JFreeChart chart = new JFreeChart(title, plot); 82 83 ChartPanel chartPanel = new ChartPanel(chart); 84 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 85 setContentPane(chartPanel); 86 87 } 88 89 100 105 public XYDataset createDataset() { 106 107 String [] sData = {"Giraffe", "Gazelle", "Zebra", "Gnu"}; 108 SampleYSymbolicDataset data 109 = new SampleYSymbolicDataset("BY Sample", 40, sData, 4, 20, 110 new String [] {"B Fall", "B Spring", "B Summer", "B Winter"}); 111 return data; 112 113 } 114 115 120 public static void main(String [] args) { 121 122 SymbolicChartDemo1 demo = new SymbolicChartDemo1("Symbolic Chart Demo 1"); 123 demo.pack(); 124 RefineryUtilities.centerFrameOnScreen(demo); 125 demo.setVisible(true); 126 127 } 128 129 } 130 131 | Popular Tags |