Display the pie chart generated by jfreechart on JSP

Source: Internet
Author: User

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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.