FileConfiguration
<? XML version = "1.0" encoding = "UTF-8"?>
<Web-app version = "2.5"
Xmlns = "http://java.sun.com/xml/ns/javaee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd>
<Servlet>
<Servlet-Name> displaychart </servlet-Name>
<Servlet-class> org. jfree. Chart. servlet. displaychart </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> displaychart </servlet-Name>
<URL-pattern>/displaychart </url-pattern>
</Servlet-mapping>
</Web-app>
<% @ Page import = "org. jfree. Chart. servlet. servletutilities" %>
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<% @ Page import = "org. jfree. data. general. defaultpiedataset, org. jfree. chart. title. texttitle, Java. AWT. font, org. jfree. chart. plot. pieplot, org. jfree. chart. jfreechart, org. jfree. chart. chartfactory, org. jfree. chart. chartframe "%>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
</Head>
<Body>
<%
Defaultpiedataset dataset = new defaultpiedataset ();
Dataset. setvalue ("propaganda department", 25 );
Dataset. setvalue ("External Department", 23 );
Dataset. setvalue ("Finance Department", 25 );
Dataset. setvalue ("Technology Department", 12 );
Jfreechart chart = chartfactory. createpiechart3d ("various departments of a community", dataset, true, true, false );
// Set the title Font of the pie chart
Chart. settitle (New texttitle ("various departments of a community", new font ("", Font. Bold, 18 )));
Pieplot plot = (pieplot) Chart. getplot ();
// Set the font of each label in the pie chart.
Plot. setlabelfont (new font ("", Font. Bold, 12 ));
// Set the legend font below the chart
Chart. getlegend (). setitemfont (new font ("", Font. Bold, 12 ));
String filename = servletutilities. savechartaspng (chart, 800,600, session );
String url = request. getcontextpath () + "/displaychart? Filename = "+ filename;
%>
</Body>
</Html>
Running result:
The generated pie chart is displayed in the temp directory of Tomcat.