1 7 8 package org.jfree.experimental.chart.demo; 9 10 import java.awt.Color ; 11 12 import javax.swing.JPanel ; 13 14 import org.jfree.chart.ChartPanel; 15 import org.jfree.chart.JFreeChart; 16 import org.jfree.chart.axis.NumberAxis; 17 import org.jfree.chart.plot.XYPlot; 18 import org.jfree.data.xy.DefaultXYZDataset; 19 import org.jfree.data.xy.XYZDataset; 20 import org.jfree.experimental.chart.renderer.LookupPaintScale; 21 import org.jfree.experimental.chart.renderer.xy.XYBlockRenderer; 22 import org.jfree.ui.ApplicationFrame; 23 import org.jfree.ui.RefineryUtilities; 24 25 28 public class XYBlockChartDemo3 extends ApplicationFrame { 29 30 35 public XYBlockChartDemo3(String title) { 36 super(title); 37 JPanel chartPanel = createDemoPanel(); 38 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 39 setContentPane(chartPanel); 40 } 41 42 private static JFreeChart createChart(XYZDataset dataset) { 43 NumberAxis xAxis = new NumberAxis("X"); 44 xAxis.setLowerMargin(0.0); 45 xAxis.setUpperMargin(0.0); 46 NumberAxis yAxis = new NumberAxis("Y"); 47 yAxis.setAutoRangeIncludesZero(false); 48 yAxis.setInverted(true); 49 yAxis.setLowerMargin(0.0); 50 yAxis.setUpperMargin(0.0); 51 yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 52 XYBlockRenderer renderer = new XYBlockRenderer(); 53 LookupPaintScale paintScale = new LookupPaintScale(); 54 paintScale.add(new Double (1.0), Color.green); 55 paintScale.add(new Double (2.0), Color.orange); 56 paintScale.add(new Double (2.99), Color.red); 57 renderer.setPaintScale(paintScale); 58 XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); 59 plot.setBackgroundPaint(Color.lightGray); 60 plot.setDomainGridlinePaint(Color.white); 61 plot.setRangeGridlinePaint(Color.white); 62 plot.setForegroundAlpha(0.66f); 63 JFreeChart chart = new JFreeChart("XYBlockChartDemo3", plot); 64 chart.removeLegend(); 65 chart.setBackgroundPaint(Color.white); 66 return chart; 67 } 68 69 77 private static void setValue(double[][] data, 78 int c, int r, double value) { 79 80 data[0][(r - 8) * 60 + c] = c; 81 data[1][(r - 8) * 60 + c] = r; 82 data[2][(r - 8) * 60 + c] = value; 83 84 } 85 86 89 private static XYZDataset createDataset() { 90 91 double[] xvalues = new double[14 * 60]; 92 double[] yvalues = new double[14 * 60]; 93 double[] zvalues = new double[14 * 60]; 94 double[][] data = new double[][] {xvalues, yvalues, zvalues}; 95 96 for (int c = 0; c < 60; c++) { 98 for (int r = 8; r < 22; r++) { 99 setValue(data, c, r, 0.0); 100 } 101 } 102 103 for (int r = 8; r < 12; r++) { 104 for (int c = 13; c < 48; c++) { 105 setValue(data, c, r, 1.0); 106 } 107 } 108 for (int r = 12; r < 20; r++) { 109 for (int c = 23; c < 43; c++) { 110 setValue(data, c, r, 1.0); 111 } 112 } 113 setValue(data, 2, 20, 2); 114 setValue(data, 5, 20, 3); 115 setValue(data, 6, 20, 3); 116 setValue(data, 7, 20, 3); 117 setValue(data, 8, 20, 3); 118 setValue(data, 9, 20, 3); 119 setValue(data, 11, 20, 3); 120 setValue(data, 17, 20, 2); 121 setValue(data, 18, 20, 2); 122 setValue(data, 19, 20, 2); 123 setValue(data, 20, 20, 2); 124 setValue(data, 22, 20, 2); 125 setValue(data, 25, 20, 2); 126 setValue(data, 28, 20, 2); 127 setValue(data, 35, 20, 2); 128 for (int c = 40; c < 60; c++) { 129 setValue(data, c, 20, 3.0); 130 } 131 132 for (int c = 23; c < 43; c++) { 133 setValue(data, c, 21, 1.0); 134 } 135 DefaultXYZDataset dataset = new DefaultXYZDataset(); 136 dataset.addSeries("Series 1", data); 137 return dataset; 138 } 139 140 145 public static JPanel createDemoPanel() { 146 return new ChartPanel(createChart(createDataset())); 147 } 148 149 154 public static void main(String [] args) { 155 XYBlockChartDemo3 demo = new XYBlockChartDemo3("Block Chart Demo 3"); 156 demo.pack(); 157 RefineryUtilities.centerFrameOnScreen(demo); 158 demo.setVisible(true); 159 } 160 161 } 162 | Popular Tags |