Jfreechart of Java reports (second lecture)

Source: Internet
Author: User
Tags pear

1. Create a fruit sales report by color using Jfreechart
1  PackageCom.wcy.chart.bar;2 3 Importjavax.servlet.http.HttpSession;4 5 Importorg.jfree.chart.ChartFactory;6 ImportOrg.jfree.chart.JFreeChart;7 Importorg.jfree.chart.plot.PlotOrientation;8 Importorg.jfree.chart.servlet.ServletUtilities;9 ImportOrg.jfree.data.category.CategoryDataset;Ten Importorg.jfree.data.general.DatasetUtilities; One  A  Public classBarChart3 { -  -      Public StaticString Genbarchart (HttpSession session)throwsexception{ the         Double[] data =New Double[][]{{1320},{720},{830},{400}}; -String[] Rowkeys = {"Apple", "banana", "orange", "pear"}; -String[] Columnkeys = {"Shenzhen"}; -Categorydataset DataSet =Datasetutilities.createcategorydataset (Rowkeys, columnkeys,data); +Jfreechart chart = Chartfactory.createbarchart3d ("Fruit Sales Chart", "Fruit", "sales", -DataSet, Plotorientation.vertical,true,true,true); +String fileName = servletutilities.savechartaspng (chart, 700, 500, session); A         returnFileName; at     } -}
1<% @pageImport= "Com.wcy.chart.bar.BarChart3"%>2<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "3pageencoding= "UTF-8"%>4<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >567<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">8<title>insert title here</title>9Ten<body> One<% AString FileName =Barchart3.genbarchart (session); -%> - the</body> -2, the use of Jfreechart create by color classification and classification by region fruit Sales report
1  PackageCom.wcy.chart.bar;2 3 Importjavax.servlet.http.HttpSession;4 5 Importorg.jfree.chart.ChartFactory;6 ImportOrg.jfree.chart.JFreeChart;7 Importorg.jfree.chart.plot.PlotOrientation;8 Importorg.jfree.chart.servlet.ServletUtilities;9 ImportOrg.jfree.data.category.CategoryDataset;Ten Importorg.jfree.data.general.DatasetUtilities; One  A  Public classBARCHART4 { -  -      Public StaticString Genbarchart (HttpSession session)throwsexception{ the         Double[] data =New Double[][]{{1390,690,542,630},{529,650,1200,690},{780,450,1300,1120},{890,640,750,500}}; -String[] Rowkeys = {"Apple", "banana", "orange", "pear"}; -String[] Columnkeys = {"Shanghai", "Beijing", "Guizhou", "Guangzhou"}; -Categorydataset DataSet =Datasetutilities.createcategorydataset (rowkeys,columnkeys,data); +Jfreechart chart = Chartfactory.createbarchart3d ("Fruit Sales Chart", "Fruit", "Sales", DataSet, Plotorientation.vertical,true,true,true); -String fileName = servletutilities.savechartaspng (chart, 700, 500, session); +         returnFileName; A     } at}
1<% @pageImport= "Com.wcy.chart.bar.BarChart4"%>2<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "3pageencoding= "UTF-8"%>4<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >567<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">8<title>insert title here</title>9Ten<body> One<% AString FileName =Barchart4.genbarchart (session); -%> - the</body> -3. Create a custom 3D columnar report using Jfreechart
1  PackageCom.wcy.chart.bar;2 3 ImportJava.awt.Color;4 5 Importjavax.servlet.http.HttpSession;6 7 Importorg.jfree.chart.ChartFactory;8 ImportOrg.jfree.chart.JFreeChart;9 ImportOrg.jfree.chart.labels.ItemLabelAnchor;Ten Importorg.jfree.chart.labels.ItemLabelPosition; One ImportOrg.jfree.chart.labels.StandardCategoryItemLabelGenerator; A ImportOrg.jfree.chart.plot.CategoryPlot; - Importorg.jfree.chart.plot.PlotOrientation; - ImportOrg.jfree.chart.renderer.category.BarRenderer3D; the Importorg.jfree.chart.servlet.ServletUtilities; - ImportOrg.jfree.data.category.CategoryDataset; - Importorg.jfree.data.general.DatasetUtilities; - ImportOrg.jfree.ui.TextAnchor; +  -  Public classBarChart5 { +  A      Public StaticString Genbarchart (HttpSession session)throwsexception{ at         Double[] data =New Double[][]{{1299,459,980,470},{590,564,300,1130},{1200,357,910,380},{509,1300,650,810}}; -String[] Rowkeys = {"Apple", "banana", "orange", "pear"}; -String[] Columnkeys = {"Shanghai", "Beijing", "Xiamen", "Guizhou"}; -Categorydataset DataSet =Datasetutilities.createcategorydataset (Rowkeys, columnkeys,data); -Jfreechart chart = Chartfactory.createbarchart3d ("Fruit Sales Chart", "Fruit", "Sales", DataSet, Plotorientation.vertical,true,true,true); -          inCategoryplot plot =Chart.getcategoryplot (); -          to         //set the grid background color + Plot.setbackgroundpaint (color.white); -         //set the grid vertical line color the Plot.setdomaingridlinepaint (color.pink); *         //Set Grid horizontal color $ Plot.setrangegridlinepaint (color.pink);Panax Notoginseng          -         //displays the value of each bar and modifies the font properties of the number theBarrenderer3d renderer=NewBarrenderer3d (); +Renderer.setbaseitemlabelgenerator (Newstandardcategoryitemlabelgenerator ()); ARenderer.setbaseitemlabelsvisible (true); the                  +Renderer.setbasepositiveitemlabelposition (Newitemlabelposition (Itemlabelanchor.outside12, Textanchor.baseline_left)); - Renderer.setitemlabelanchoroffset (10D);  $                  $         //set the distance between parallel bars -Renderer.setitemmargin (0.4); -                  the plot.setrenderer (renderer); -                 WuyiString fileName = servletutilities.savechartaspng (chart, 700, 500, session); the         returnFileName; -     } Wu}
1<% @pageImport= "Com.wcy.chart.bar.BarChart5"%>2<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "3pageencoding= "UTF-8"%>4<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >567<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">8<title>insert title here</title>9Ten<body> One<% AString FileName =Barchart5.genbarchart (session); -%> - the</body> -

Statement: This program code himself is only used for learning summary, non-original, if there is infringement, contact me.

Jfreechart of Java reports (second lecture)

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.