资源描述:
《jfreechart_折线图,饼图,柱状图,堆栈柱状图(二维图)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、最近使用jfreechart来生成统计图,使用了折线图,饼图等,因为用的1.0.8a版的jfreechart,与1.0.0版本的地方有很多不同,而且图片生成清晰度比老版的高,如下是我做的demo.1.所需包(1)jfreechart-1.0.8a.jar(2)jcommon-1.0.12.jar2.运行环境JDK1.53.源代码importjava.awt.Color;importjava.awt.Font;importjava.io.File;importjava.io.FileOutputStream;importjava.text.DecimalFormat;importj
2、ava.text.NumberFormat;importorg.jfree.chart.ChartFactory;importorg.jfree.chart.ChartUtilities;importorg.jfree.chart.JFreeChart;importorg.jfree.chart.axis.CategoryAxis;importorg.jfree.chart.axis.CategoryLabelPositions;importorg.jfree.chart.axis.NumberAxis;importorg.jfree.chart.axis.ValueAxis;i
3、mportorg.jfree.chart.labels.StandardCategoryItemLabelGenerator;importorg.jfree.chart.labels.StandardPieSectionLabelGenerator;importorg.jfree.chart.plot.CategoryPlot;importorg.jfree.chart.plot.PiePlot3D;importorg.jfree.chart.plot.PlotOrientation;importorg.jfree.chart.renderer.category.BarRende
4、rer;importorg.jfree.chart.renderer.category.LineAndShapeRenderer;importorg.jfree.chart.renderer.category.StackedBarRenderer;importorg.jfree.chart.title.TextTitle;importorg.jfree.data.category.CategoryDataset;importorg.jfree.data.general.DatasetUtilities;importorg.jfree.data.general.DefaultPie
5、Dataset;importorg.jfree.data.general.PieDataset;/***实际取色的时候一定要16位的,这样比较准确*@authornew*/publicclassCreateChartServiceImpl{privatestaticfinalStringCHART_PATH="E:/test/";publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubCreateChartServiceImplpm=newCreateChartServiceImpl();//生成饼状图pm
6、.makePieChart();//生成单组柱状图pm.makeBarChart();//生成多组柱状图pm.makeBarGroupChart();//生成堆积柱状图pm.makeStackedBarChart();//生成折线图pm.makeLineAndShapeChart();}/***生成折线图*/publicvoidmakeLineAndShapeChart(){double[][]data=newdouble[][]{{672,766,223,540,126},{325,521,210,340,106},{332,256,523,240,526}};String[]
7、rowKeys={"苹果","梨子","葡萄"};String[]columnKeys={"北京","上海","广州","成都","深圳"};CategoryDatasetdataset=getBarData(data,rowKeys,columnKeys);createTimeXYChar("折线图","x轴","y轴",dataset,"lineAndShap.png");}/***生成分组的柱状图*/publicvoidmakeBarGroupChart(){double[