1 39 40 package org.jfree.chart.demo; 41 42 import java.awt.Insets ; 43 import java.io.BufferedOutputStream ; 44 import java.io.File ; 45 import java.io.FileOutputStream ; 46 import java.io.IOException ; 47 import java.io.OutputStream ; 48 import java.io.PrintWriter ; 49 50 import org.jfree.chart.ChartFactory; 51 import org.jfree.chart.ChartRenderingInfo; 52 import org.jfree.chart.ChartUtilities; 53 import org.jfree.chart.JFreeChart; 54 import org.jfree.chart.entity.StandardEntityCollection; 55 import org.jfree.chart.labels.StandardPieItemLabelGenerator; 56 import org.jfree.chart.plot.PiePlot; 57 import org.jfree.chart.urls.StandardPieURLGenerator; 58 import org.jfree.data.DefaultPieDataset; 59 60 65 public class ImageMapDemo2 { 66 67 70 public ImageMapDemo2() { 71 } 72 73 78 public static void main(String [] args) { 79 80 DefaultPieDataset data = new DefaultPieDataset(); 82 data.setValue("One", new Double (43.2)); 83 data.setValue("Two", new Double (10.0)); 84 data.setValue("Three", new Double (27.5)); 85 data.setValue("Four", new Double (17.5)); 86 data.setValue("Five", new Double (11.0)); 87 data.setValue("Six", new Double (19.4)); 88 89 JFreeChart chart = null; 90 boolean drilldown = true; 91 92 if (drilldown) { 94 PiePlot plot = new PiePlot(data); 95 plot.setInsets(new Insets (0, 5, 5, 5)); 96 plot.setItemLabelGenerator(new StandardPieItemLabelGenerator()); 97 plot.setURLGenerator(new StandardPieURLGenerator("pie_chart_detail.jsp")); 98 chart = new JFreeChart("Pie Chart Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, true); 99 } 100 else { 101 chart = ChartFactory.createPieChart( 102 "Pie Chart Demo 1", data, true, true, 106 false 107 ); 108 } 109 chart.setBackgroundPaint(java.awt.Color.white); 110 111 122 try { 124 ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); 125 File file1 = new File ("piechart100.png"); 126 ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); 127 128 File file2 = new File ("piechart100.html"); 130 OutputStream out = new BufferedOutputStream (new FileOutputStream (file2)); 131 PrintWriter writer = new PrintWriter (out); 132 writer.println("<HTML>"); 133 writer.println("<HEAD><TITLE>JFreeChart Image Map Demo 2</TITLE></HEAD>"); 134 writer.println("<BODY>"); 135 ChartUtilities.writeImageMap(writer, "chart", info); 136 writer.println("<IMG SRC=\"piechart100.png\" " 137 + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); 138 writer.println("</BODY>"); 139 writer.println("</HTML>"); 140 writer.close(); 141 142 } 143 catch (IOException e) { 144 System.out.println(e.toString()); 145 } 146 147 } 148 149 } 150 | Popular Tags |