Use jfreechart to draw 2D pie chart images on the JSP page

Source: Internet
Author: User

<% @ Page Language = "Java" pageencoding = "UTF-8" %> <br/> <% @ page import = "org. jfree. data. general. defaultpiedataset, <br/> Org. jfree. chart. jfreechart, <br/> Org. jfree. chart. chartfactory, <br/> Org. jfree. chart. servlet. servletutilities "%> <br/> <% <br/> defaultpiedataset DPD = new defaultpiedataset (); <br/> DPD. setvalue ("Administrator", 25); <br/> DPD. setvalue ("market personnel", 25); <br/> DPD. setvalue ("Developer", 45); <br/> DPD. setva Lue ("other personnel", 10); <br/> jfreechart chart = chartfactory. createpiechart ("A company's organizational structure 2D pie chart", DPD, true, false, false); <br/> string filename = servletutilities. savechartaspng (chart, 1024,768, session); <br/> string url = request. getcontextpath () + "/servlet/displaychart? Filename = "+ filename; <br/> %> <br/> <br/> <% -- <br/> ======================================== ========================================================== ====================================< br/> Org. jfree. chart. servlet. the displaychart class inherits javax. servlet. HTTP. httpservlet. It is described as follows <br/> Servlet used for streaming charts to the client browser from the temporary directory <br/> you need to add this servlet and mapping to your deployment descriptorin order to get it To Work <br/> Translation: this is a Servlet used to send images to the client browser in the form of a stream from the temporary directory <br/> to make it work, you need to deploy the descriptor (web. XML) add this servlet and Its ing <br/> because we need to display images on the JSP page, we need to go to the Web. display the displaychart in XML as follows: <br/> <servlet> <br/> <servlet-Name> displaychar T </servlet-Name> <br/> <servlet-class> Org. jfree. chart. servlet. displaychart </servlet-class> <br/> </servlet> <br/> <servlet-mapping> <br/> <servlet-Name> displaychart </servlet-Name> <br/> <URL-pattern>/servlet/displaychart </url-pattern> <br/> </servlet-mapping> <br/>===== ========================================================== ========================================================== ============< br/> chartutilities. writechartasjpeg () is for JA Va application <br/> servletutilities. savechartaspng () is web-oriented <br/> ============================================ ========================================================== ======================================< br/> savechartaspng () the returned value is the name of the generated image. The generated image is saved in the temporary directory of the server. <br/> the temporary directory of Tomcat 6 is D: /program files/tomcat6/TEMP directory <br/> here, our Java code is written in the JSP page <br/> so every time you access or refresh the page, an image is generated in the temporary directory of the server. <br/> the name of the image is jfreechart-62412.png.] <br/>============== = ========================================================== ==============================================================< Br/> when used in Web. when the servlet named displaychart is configured in XML <br/> it searches for images in the temporary directory of the server based on its filename, <br/> therefore, the filename parameter should be specified for displaychart, that is, [displaychart? The filename =] part is fixed <br/> ============================== ========================================================== ======================================< br/> -- %>

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.