1 41 42 package org.jfree.chart.demo; 43 44 import java.awt.Color ; 45 import java.awt.Font ; 46 import java.text.DecimalFormat ; 47 48 import org.jfree.chart.ChartFrame; 49 import org.jfree.chart.JFreeChart; 50 import org.jfree.chart.axis.CategoryAxis; 51 import org.jfree.chart.axis.NumberAxis; 52 import org.jfree.chart.axis.NumberTickUnit; 53 import org.jfree.chart.labels.IntervalCategoryItemLabelGenerator; 54 import org.jfree.chart.plot.CategoryPlot; 55 import org.jfree.chart.plot.PlotOrientation; 56 import org.jfree.chart.renderer.IntervalBarRenderer; 57 import org.jfree.chart.renderer.ItemLabelAnchor; 58 import org.jfree.chart.renderer.ItemLabelPosition; 59 import org.jfree.data.DefaultIntervalCategoryDataset; 60 import org.jfree.ui.TextAnchor; 61 62 67 public class IntervalBarChartDemo1 { 68 69 70 private static final String [] CATEGORIES = {"1", "3", "5", "10", "20"}; 71 72 73 private static Font labelFont = null; 74 75 76 private static Font titleFont = null; 77 78 79 private JFreeChart chart = null; 80 81 static { 82 labelFont = new Font ("Helvetica", Font.PLAIN, 10); 83 titleFont = new Font ("Helvetica", Font.BOLD, 14); 84 } 85 86 89 public IntervalBarChartDemo1() { 90 91 DefaultIntervalCategoryDataset data = null; 92 double[][] lows = {{-.0315, .0159, .0306, .0453, .0557}}; 93 double[][] highs = {{.1931, .1457, .1310, .1163, .1059}}; 94 data = new DefaultIntervalCategoryDataset(lows, highs); 95 data.setCategoryKeys(CATEGORIES); 96 97 String title = "Strategie Sicherheit"; 98 String xTitle = "Zeitraum (in Jahren)"; 99 String yTitle = "Performance"; 100 CategoryAxis xAxis = new CategoryAxis(xTitle); 101 xAxis.setLabelFont(titleFont); 102 xAxis.setTickLabelFont(labelFont); 103 xAxis.setTickMarksVisible(false); 104 NumberAxis yAxis = new NumberAxis(yTitle); 105 yAxis.setLabelFont(titleFont); 106 yAxis.setTickLabelFont(labelFont); 107 yAxis.setRange(-0.2, 0.40); 108 DecimalFormat formatter = new DecimalFormat ("0.##%"); 109 yAxis.setTickUnit(new NumberTickUnit(0.05, formatter)); 110 111 IntervalBarRenderer renderer = new IntervalBarRenderer(); 112 renderer.setSeriesPaint(0, new Color (51, 102, 153)); 113 renderer.setItemLabelGenerator(new IntervalCategoryItemLabelGenerator()); 114 renderer.setItemLabelsVisible(true); 115 renderer.setItemLabelPaint(Color.white); 116 ItemLabelPosition p = new ItemLabelPosition( 117 ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 0.0 118 ); 119 renderer.setPositiveItemLabelPosition(p); 120 121 CategoryPlot plot = new CategoryPlot(data, xAxis, yAxis, renderer); 122 plot.setBackgroundPaint(Color.lightGray); 123 plot.setOutlinePaint(Color.white); 124 plot.setOrientation(PlotOrientation.VERTICAL); 125 126 chart = new JFreeChart(title, titleFont, plot, false); 127 chart.setBackgroundPaint(Color.white); 128 } 129 130 141 146 public JFreeChart getChart() { 147 return chart; 148 } 149 150 155 public static void main(String [] args) { 156 IntervalBarChartDemo1 sample = new IntervalBarChartDemo1(); 157 JFreeChart chart = sample.getChart(); 158 ChartFrame frame = new ChartFrame("Interval Bar Chart Demo", chart); 159 frame.pack(); 160 frame.setVisible(true); 161 } 162 } 163 | Popular Tags |