1 36 37 package org.jfree.chart.demo; 38 39 import java.awt.Color ; 40 41 import org.jfree.chart.ChartPanel; 42 import org.jfree.chart.JFreeChart; 43 import org.jfree.chart.axis.CategoryAxis; 44 import org.jfree.chart.axis.NumberAxis; 45 import org.jfree.chart.axis.ValueAxis; 46 import org.jfree.chart.plot.CategoryPlot; 47 import org.jfree.chart.renderer.LayeredBarRenderer; 48 import org.jfree.data.CategoryDataset; 49 import org.jfree.data.DatasetUtilities; 50 import org.jfree.ui.ApplicationFrame; 51 import org.jfree.ui.RefineryUtilities; 52 53 58 public class LayeredBarChartDemo2 extends ApplicationFrame { 59 60 65 public LayeredBarChartDemo2(String title) { 66 67 super(title); 68 69 double[][] data = new double[][] { 71 {41.0, 33.0, 22.0, 64.0, 42.0, 62.0, 22.0, 14.0}, 72 {55.0, 63.0, 55.0, 48.0, 54.0, 37.0, 41.0, 39.0}, 73 {57.0, 75.0, 43.0, 33.0, 63.0, 46.0, 57.0, 33.0} 74 }; 75 76 CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", 77 "Factor ", 78 data); 79 80 CategoryAxis categoryAxis = new CategoryAxis("Category"); 82 ValueAxis valueAxis = new NumberAxis("Score (%)"); 83 84 85 CategoryPlot plot = new CategoryPlot(dataset, 86 categoryAxis, 87 valueAxis, 88 new LayeredBarRenderer()); 89 90 plot.setOrientation(org.jfree.chart.plot.PlotOrientation.VERTICAL); 91 JFreeChart chart = new JFreeChart( 92 "Layered Bar Chart Demo 2", 93 JFreeChart.DEFAULT_TITLE_FONT, 94 plot, 95 true 96 ); 97 98 chart.setBackgroundPaint(Color.lightGray); 100 101 LayeredBarRenderer renderer = (LayeredBarRenderer) plot.getRenderer(); 102 103 renderer.setSeriesBarWidth(0, 1.0); 106 renderer.setSeriesBarWidth(1, 0.7); 107 renderer.setSeriesBarWidth(2, 0.5); 108 109 renderer.setItemMargin(0.01); 110 111 CategoryAxis domainAxis = plot.getDomainAxis(); 112 domainAxis.setCategoryMargin(0.25); 113 domainAxis.setUpperMargin(0.05); 114 domainAxis.setLowerMargin(0.05); 115 116 ChartPanel chartPanel = new ChartPanel(chart); 118 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 119 setContentPane(chartPanel); 120 121 } 122 123 134 139 public static void main(String [] args) { 140 141 LayeredBarChartDemo2 demo = new LayeredBarChartDemo2("Layered Bar Chart Demo 2"); 142 demo.pack(); 143 RefineryUtilities.centerFrameOnScreen(demo); 144 demo.setVisible(true); 145 146 } 147 148 } 149 | Popular Tags |