1 38 39 package org.jfree.chart.demo; 40 41 import java.awt.Color ; 42 import java.text.NumberFormat ; 43 44 import org.jfree.chart.ChartFactory; 45 import org.jfree.chart.ChartPanel; 46 import org.jfree.chart.JFreeChart; 47 import org.jfree.chart.TextTitle; 48 import org.jfree.chart.axis.CategoryAxis; 49 import org.jfree.chart.axis.NumberAxis; 50 import org.jfree.chart.plot.CategoryPlot; 51 import org.jfree.chart.plot.DatasetRenderingOrder; 52 import org.jfree.chart.plot.PlotOrientation; 53 import org.jfree.chart.renderer.LineAndShapeRenderer; 54 import org.jfree.data.CategoryDataset; 55 import org.jfree.data.DataUtilities; 56 import org.jfree.data.DatasetUtilities; 57 import org.jfree.data.DefaultKeyedValues; 58 import org.jfree.data.KeyedValues; 59 import org.jfree.ui.ApplicationFrame; 60 import org.jfree.ui.RefineryUtilities; 61 import org.jfree.util.SortOrder; 62 63 68 public class ParetoChartDemo extends ApplicationFrame { 69 70 75 public ParetoChartDemo(String title) { 76 77 super(title); 78 79 DefaultKeyedValues data = new DefaultKeyedValues(); 80 data.addValue("C", new Integer (4843)); 81 data.addValue("C++", new Integer (2098)); 82 data.addValue("C#", new Integer (26)); 83 data.addValue("Java", new Integer (1901)); 84 data.addValue("Perl", new Integer (2507)); 85 data.addValue("PHP", new Integer (1689)); 86 data.addValue("Python", new Integer (948)); 87 data.addValue("Ruby", new Integer (100)); 88 data.addValue("SQL", new Integer (263)); 89 data.addValue("Unix Shell", new Integer (485)); 90 91 data.sortByValues(SortOrder.DESCENDING); 92 KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); 93 CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Languages", data); 94 95 JFreeChart chart = ChartFactory.createBarChart( 97 "Freshmeat Software Projects", "Language", "Projects", dataset, PlotOrientation.VERTICAL, 102 true, true, 104 false 105 ); 106 107 chart.addSubtitle(new TextTitle("By Programming Language")); 109 chart.addSubtitle(new TextTitle("As at 5 March 2003")); 110 111 chart.setBackgroundPaint(new Color (0xBBBBDD)); 113 114 CategoryPlot plot = chart.getCategoryPlot(); 116 117 CategoryAxis domainAxis = plot.getDomainAxis(); 118 domainAxis.setLowerMargin(0.02); 119 domainAxis.setUpperMargin(0.02); 120 121 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 123 rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 124 125 LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); 126 127 CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative", cumulative); 128 NumberAxis axis2 = new NumberAxis("Percent"); 129 axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); 130 plot.setSecondaryRangeAxis(0, axis2); 131 plot.setSecondaryDataset(0, dataset2); 132 plot.setSecondaryRenderer(0, renderer2); 133 plot.mapSecondaryDatasetToRangeAxis(0, new Integer (0)); 134 135 plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); 136 138 ChartPanel chartPanel = new ChartPanel(chart); 140 chartPanel.setPreferredSize(new java.awt.Dimension (550, 270)); 141 setContentPane(chartPanel); 142 143 } 144 145 156 161 public static void main(String [] args) { 162 163 ParetoChartDemo demo = new ParetoChartDemo("Pareto Chart Demo"); 164 demo.pack(); 165 RefineryUtilities.centerFrameOnScreen(demo); 166 demo.setVisible(true); 167 168 } 169 170 171 } 172 | Popular Tags |