1 38 package org.jfree.chart.demo; 39 40 import java.io.BufferedOutputStream ; 41 import java.io.File ; 42 import java.io.FileOutputStream ; 43 import java.io.IOException ; 44 import java.io.OutputStream ; 45 import java.io.PrintWriter ; 46 import java.text.ParseException ; 47 import java.text.SimpleDateFormat ; 48 import java.util.ArrayList ; 49 50 import org.jfree.chart.ChartRenderingInfo; 51 import org.jfree.chart.ChartUtilities; 52 import org.jfree.chart.JFreeChart; 53 import org.jfree.chart.axis.DateAxis; 54 import org.jfree.chart.axis.NumberAxis; 55 import org.jfree.chart.axis.ValueAxis; 56 import org.jfree.chart.entity.StandardEntityCollection; 57 import org.jfree.chart.labels.CustomXYToolTipGenerator; 58 import org.jfree.chart.plot.XYPlot; 59 import org.jfree.chart.renderer.StandardXYItemRenderer; 60 import org.jfree.chart.urls.StandardXYURLGenerator; 61 import org.jfree.data.XYSeries; 62 import org.jfree.data.XYSeriesCollection; 63 64 69 public class ImageMapDemo3 { 70 71 74 public ImageMapDemo3() { 75 super(); 76 } 77 78 85 public static void main(String [] args) throws ParseException { 86 87 SimpleDateFormat sdf = new SimpleDateFormat ("dd-MMM-yyyy"); 89 XYSeries dataSeries = new XYSeries("Curve data"); 90 ArrayList toolTips = new ArrayList (); 91 dataSeries.add(sdf.parse("01-Jul-2002").getTime(), 5.22); 92 toolTips.add("1D - 5.22"); 93 dataSeries.add(sdf.parse("02-Jul-2002").getTime(), 5.18); 94 toolTips.add("2D - 5.18"); 95 dataSeries.add(sdf.parse("03-Jul-2002").getTime(), 5.23); 96 toolTips.add("3D - 5.23"); 97 dataSeries.add(sdf.parse("04-Jul-2002").getTime(), 5.15); 98 toolTips.add("4D - 5.15"); 99 dataSeries.add(sdf.parse("05-Jul-2002").getTime(), 5.22); 100 toolTips.add("5D - 5.22"); 101 dataSeries.add(sdf.parse("06-Jul-2002").getTime(), 5.25); 102 toolTips.add("6D - 5.25"); 103 dataSeries.add(sdf.parse("07-Jul-2002").getTime(), 5.31); 104 toolTips.add("7D - 5.31"); 105 dataSeries.add(sdf.parse("08-Jul-2002").getTime(), 5.36); 106 toolTips.add("8D - 5.36"); 107 XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries); 108 CustomXYToolTipGenerator ttg = new CustomXYToolTipGenerator(); 109 ttg.addToolTipSeries(toolTips); 110 111 StandardXYURLGenerator urlg = new StandardXYURLGenerator("xy_details.jsp"); 113 ValueAxis timeAxis = new DateAxis(""); 114 NumberAxis valueAxis = new NumberAxis(""); 115 valueAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, null); 117 StandardXYItemRenderer sxyir = new StandardXYItemRenderer( 118 StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES, 119 ttg, urlg); 120 sxyir.setShapesFilled(true); 121 plot.setRenderer(sxyir); 122 JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false); 123 chart.setBackgroundPaint(java.awt.Color.white); 124 125 136 try { 138 ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); 139 File file1 = new File ("xychart100.png"); 140 ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); 141 142 File file2 = new File ("xychart100.html"); 144 OutputStream out = new BufferedOutputStream (new FileOutputStream (file2)); 145 PrintWriter writer = new PrintWriter (out); 146 writer.println("<HTML>"); 147 writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>"); 148 writer.println("<BODY>"); 149 ChartUtilities.writeImageMap(writer, "chart", info); 150 writer.println("<IMG SRC=\"xychart100.png\" " 151 + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); 152 writer.println("</BODY>"); 153 writer.println("</HTML>"); 154 writer.close(); 155 156 } 157 catch (IOException e) { 158 System.out.println(e.toString()); 159 } 160 return; 161 } 162 } 163 | Popular Tags |