JSP/Java to generate bar charts and pie charts... Jfreechart

Source: Internet
Author: User

Recently, we have seen useful things in the case of chaos in csdn. We have used jfreechart to achieve a lot of complex graphics,

Reprinted URL: http://www.java2000.net/f30

 

Below are a few simple examples:

<% @ Page Language = "Java" pageencoding = "UTF-8" %> <br/> <% @ page import = "org. jfree. data. category. *, org. jfree. chart. *, org. jfree. chart. plot. * "%> <br/> <% <br/> out. clearbuffer (); <br/> response. setcontenttype ("image/JPEG"); <br/> defaultcategorydataset dataset = new defaultcategorydataset (); <br/> dataset. addvalue (610, "Taian", "test1"); <br/> dataset. addvalue (540, "Taian", "Test2"); <br/> dataset. addvalue (320, "Taian", "test3"); <br/> dataset. addvalue (370, "Taian", "test4"); <br/> dataset. addvalue (130, "Taian", "test5"); <br/> jfreechart chart = chartfactory. createbarchart ("biangji", "xiaoliang", "roulei", dataset, plotorientation. vertical, false); <br/> JAVA. io. outputstream OS = response. getoutputstream (); <br/> javax. imageIO. imageIO. write (chart. createbufferedimage (500,300), "Jpeg", OS); <br/> OS. flush (); <br/> OS. close (); <br/>%> <br/>

 

Import Org. jfree. chart. chartfactory; <br/> Import Org. jfree. chart. chartframe; <br/> Import Org. jfree. chart. jfreechart; <br/> Import Org. jfree. data. general. defaultpiedataset; <br/> public class first {<br/> Public static void main (string [] ARGs) {</P> <p> defaultpiedataset DATA = new defapipiedataset (); <br/> data. setvalue ("catagory 1", 43.2); <br/> data. setvalue ("catagory 2", 27.9); <br/> data. setvalue ("catagory 3", 79.5); <br/> jfreechart chart = chartfactory. createpiechart ("sample pie chart", Data, true, true, false); <br/> chartframe frame = new chartframe ("first", chart); <br/> frame. pack (); <br/> frame. setvisible (true); <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.