1 39 40 package org.jfree.chart.demo; 41 42 import java.io.BufferedOutputStream ; 43 import java.io.File ; 44 import java.io.FileOutputStream ; 45 import java.io.IOException ; 46 import java.io.OutputStream ; 47 import java.io.PrintWriter ; 48 49 import org.jfree.chart.ChartFactory; 50 import org.jfree.chart.ChartRenderingInfo; 51 import org.jfree.chart.ChartUtilities; 52 import org.jfree.chart.JFreeChart; 53 import org.jfree.chart.axis.CategoryAxis; 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.StandardCategoryItemLabelGenerator; 58 import org.jfree.chart.plot.CategoryPlot; 59 import org.jfree.chart.plot.PlotOrientation; 60 import org.jfree.chart.renderer.BarRenderer; 61 import org.jfree.chart.urls.StandardCategoryURLGenerator; 62 import org.jfree.data.CategoryDataset; 63 import org.jfree.data.DatasetUtilities; 64 65 70 public class ImageMapDemo1 { 71 72 75 public ImageMapDemo1() { 76 } 77 78 83 public static void main(String [] args) { 84 85 double[][] data = new double[][] { 87 {56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0}, 88 {37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0}, 89 {43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0} 90 }; 91 CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data); 92 93 JFreeChart chart = null; 94 boolean drilldown = true; 95 96 if (drilldown) { 97 CategoryAxis categoryAxis = new CategoryAxis("Category"); 98 ValueAxis valueAxis = new NumberAxis("Value"); 99 BarRenderer renderer = new BarRenderer(); 100 renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); 101 renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp")); 102 CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); 103 plot.setOrientation(PlotOrientation.VERTICAL); 104 chart = new JFreeChart("Vertical Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); 105 } 106 else { 107 chart = ChartFactory.createBarChart( 108 "Vertical Bar Chart", "Category", "Value", dataset, PlotOrientation.VERTICAL, 113 true, true, 115 false 116 ); 117 } 118 chart.setBackgroundPaint(java.awt.Color.white); 119 120 131 try { 133 ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); 134 File file1 = new File ("barchart100.png"); 135 ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); 136 137 File file2 = new File ("barchart100.html"); 139 OutputStream out = new BufferedOutputStream (new FileOutputStream (file2)); 140 PrintWriter writer = new PrintWriter (out); 141 writer.println("<HTML>"); 142 writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>"); 143 writer.println("<BODY>"); 144 ChartUtilities.writeImageMap(writer, "chart", info); 145 writer.println("<IMG SRC=\"barchart100.png\" " 146 + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); 147 writer.println("</BODY>"); 148 writer.println("</HTML>"); 149 writer.close(); 150 151 } 152 catch (IOException e) { 153 System.out.println(e.toString()); 154 } 155 156 } 157 158 } 159 | Popular Tags |