1 41 42 package org.jfree.chart.demo; 43 44 import java.awt.BasicStroke ; 45 import java.awt.Color ; 46 import java.awt.Font ; 47 48 import org.jfree.chart.ChartFactory; 49 import org.jfree.chart.ChartPanel; 50 import org.jfree.chart.IntervalMarker; 51 import org.jfree.chart.JFreeChart; 52 import org.jfree.chart.axis.MarkerAxisBand; 53 import org.jfree.chart.axis.NumberAxis; 54 import org.jfree.chart.plot.CategoryPlot; 55 import org.jfree.chart.plot.PlotOrientation; 56 import org.jfree.data.CategoryDataset; 57 import org.jfree.data.DatasetUtilities; 58 import org.jfree.ui.ApplicationFrame; 59 import org.jfree.ui.RefineryUtilities; 60 61 66 public class BarChartDemo5 extends ApplicationFrame { 67 68 73 public BarChartDemo5(String title) { 74 75 super(title); 76 77 double[][] data = new double[][] { 79 {1.0, 43.0, 35.0, 58.0, 54.0, 77.0, 71.0, 89.0}, 80 {54.0, 75.0, 63.0, 83.0, 43.0, 46.0, 27.0, 13.0}, 81 {41.0, 33.0, 22.0, 34.0, 62.0, 32.0, 42.0, 34.0} 82 }; 83 84 CategoryDataset dataset = DatasetUtilities.createCategoryDataset( 85 "Series ", 86 "Factor ", 87 data 88 ); 89 90 JFreeChart chart = ChartFactory.createBarChart( 92 "Horizontal Bar Chart", "Category", "Score (%)", dataset, PlotOrientation.HORIZONTAL, 97 true, true, 99 false 100 ); 101 102 104 chart.setBackgroundPaint(Color.lightGray); 105 106 CategoryPlot plot = chart.getCategoryPlot(); 108 109 plot.getRenderer().setSeriesPaint(0, new Color (0, 0, 255)); 110 plot.getRenderer().setSeriesPaint(1, new Color (75, 75, 255)); 111 plot.getRenderer().setSeriesPaint(2, new Color (150, 150, 255)); 112 113 NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); 115 rangeAxis.setRange(0.0, 100.0); 116 rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 117 118 NumberAxis hna = rangeAxis; 119 MarkerAxisBand band = new MarkerAxisBand(hna, 2.0, 2.0, 2.0, 2.0, 120 new Font ("SansSerif", Font.PLAIN, 9)); 121 122 IntervalMarker m1 = new IntervalMarker(0.0, 33.0, "Low", Color.gray, 123 new BasicStroke (0.5f), Color.green, 0.75f); 124 IntervalMarker m2 = new IntervalMarker(33.0, 66.0, "Medium", Color.gray, 125 new BasicStroke (0.5f), Color.orange, 0.75f); 126 IntervalMarker m3 = new IntervalMarker(66.0, 100.0, "High", Color.gray, 127 new BasicStroke (0.5f), Color.red, 0.75f); 128 band.addMarker(m1); 129 band.addMarker(m2); 130 band.addMarker(m3); 131 hna.setMarkerBand(band); 132 134 ChartPanel chartPanel = new ChartPanel(chart); 136 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 137 setContentPane(chartPanel); 138 139 } 140 141 152 157 public static void main(String [] args) { 158 159 BarChartDemo5 demo = new BarChartDemo5("Horizontal Bar Chart Demo"); 160 demo.pack(); 161 RefineryUtilities.centerFrameOnScreen(demo); 162 demo.setVisible(true); 163 164 } 165 166 } 167 | Popular Tags |