KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > demo > ImageMapDemo2


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * ------------------
23  * ImageMapDemo2.java
24  * ------------------
25  * (C) Copyright 2002, 2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): Richard Atkinson (richard_c_atkinson@ntlworld.com);
29  *
30  * $Id: ImageMapDemo2.java,v 1.7 2003/11/28 10:57:33 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 26-Jun-2002 : Version 1 (DG);
35  * 05-Aug-2002 : Modified to demonstrate hrefs and alt tags in image map (RA);
36  * 10-Oct-2002 : Fixed errors reported by Checkstyle (DG);
37  *
38  */

39
40 package org.jfree.chart.demo;
41
42 import java.awt.Insets JavaDoc;
43 import java.io.BufferedOutputStream JavaDoc;
44 import java.io.File JavaDoc;
45 import java.io.FileOutputStream JavaDoc;
46 import java.io.IOException JavaDoc;
47 import java.io.OutputStream JavaDoc;
48 import java.io.PrintWriter JavaDoc;
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 /**
61  * Another demo showing how to create an HTML image map with JFreeChart.
62  *
63  * @author David Gilbert
64  */

65 public class ImageMapDemo2 {
66
67     /**
68      * Default constructor.
69      */

70     public ImageMapDemo2() {
71     }
72
73     /**
74      * The starting point for the demo.
75      *
76      * @param args ignored.
77      */

78     public static void main(String JavaDoc[] args) {
79
80         // create a chart
81
DefaultPieDataset data = new DefaultPieDataset();
82         data.setValue("One", new Double JavaDoc(43.2));
83         data.setValue("Two", new Double JavaDoc(10.0));
84         data.setValue("Three", new Double JavaDoc(27.5));
85         data.setValue("Four", new Double JavaDoc(17.5));
86         data.setValue("Five", new Double JavaDoc(11.0));
87         data.setValue("Six", new Double JavaDoc(19.4));
88
89         JFreeChart chart = null;
90         boolean drilldown = true;
91
92         // create the chart...
93
if (drilldown) {
94             PiePlot plot = new PiePlot(data);
95             plot.setInsets(new Insets JavaDoc(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", // chart title
103
data, // data
104
true, // include legend
105
true,
106                 false
107             );
108         }
109         chart.setBackgroundPaint(java.awt.Color.white);
110
111         // ****************************************************************************
112
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
113
// * Please note that commercial support and documentation is available from: *
114
// * *
115
// * http://www.object-refinery.com/jfreechart/support.html *
116
// * *
117
// * This is not only a great service for developers, but is a VERY IMPORTANT *
118
// * source of funding for the JFreeChart project. Please support us so that *
119
// * we can continue developing free software. *
120
// ****************************************************************************
121

122         // save it to an image
123
try {
124             ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
125             File JavaDoc file1 = new File JavaDoc("piechart100.png");
126             ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
127
128             // write an HTML page incorporating the image with an image map
129
File JavaDoc file2 = new File JavaDoc("piechart100.html");
130             OutputStream JavaDoc out = new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(file2));
131             PrintWriter JavaDoc writer = new PrintWriter JavaDoc(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 JavaDoc e) {
144             System.out.println(e.toString());
145         }
146
147     }
148
149 }
150
Popular Tags