1 37 38 package org.jfree.chart.demo; 39 40 import org.jfree.chart.ChartPanel; 41 import org.jfree.chart.JFreeChart; 42 import org.jfree.chart.axis.NumberAxis; 43 import org.jfree.chart.plot.PlotOrientation; 44 import org.jfree.chart.plot.XYPlot; 45 import org.jfree.chart.renderer.StandardXYItemRenderer; 46 import org.jfree.chart.renderer.XYItemRenderer; 47 import org.jfree.data.XYDataset; 48 import org.jfree.data.XYSeries; 49 import org.jfree.data.XYSeriesCollection; 50 import org.jfree.ui.ApplicationFrame; 51 import org.jfree.ui.RefineryUtilities; 52 53 59 public class WaterTemperatureDemo extends ApplicationFrame { 60 61 66 public WaterTemperatureDemo(String title) { 67 68 super(title); 69 XYDataset dataset = createDataset(); 70 71 NumberAxis rangeAxis = new NumberAxis("Temperature"); 72 rangeAxis.setRange(-0.55, -0.15); 73 74 NumberAxis domainAxis = new NumberAxis("Depth"); 75 domainAxis.setInverted(true); 76 domainAxis.setRange(0.0, 35.0); 77 domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); 78 79 XYItemRenderer renderer = new StandardXYItemRenderer(); 80 81 XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); 82 plot.setOrientation(PlotOrientation.HORIZONTAL); 83 JFreeChart chart = new JFreeChart("Water Temperature By Depth", plot); 84 85 ChartPanel chartPanel = new ChartPanel(chart); 86 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 87 setContentPane(chartPanel); 88 89 } 90 91 96 private XYDataset createDataset() { 97 98 XYSeries series = new XYSeries("Zone 1"); 99 series.add(1.0, -0.5); 100 series.add(5.0, -0.5); 101 series.add(10.0, -0.4); 102 series.add(15.0, -0.4); 103 series.add(20.0, -0.3); 104 series.add(25.0, -0.3); 105 series.add(30.0, -0.2); 106 series.add(35.0, -0.2); 107 108 return new XYSeriesCollection(series); 109 110 } 111 112 123 128 public static void main(String [] args) { 129 130 WaterTemperatureDemo demo = new WaterTemperatureDemo("Water Temperature Demo"); 131 demo.pack(); 132 RefineryUtilities.centerFrameOnScreen(demo); 133 demo.setVisible(true); 134 135 } 136 137 } 138 | Popular Tags |