jfreechart生成折线图饼柱状图堆栈_第1页
jfreechart生成折线图饼柱状图堆栈_第2页
jfreechart生成折线图饼柱状图堆栈_第3页
jfreechart生成折线图饼柱状图堆栈_第4页
jfreechart生成折线图饼柱状图堆栈_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

最近公司使用jchart来生成统计图使用了折线图饼图等因为用的1.0.8a版的 与1.0.0版本的地方有很多不同,而且生成清晰度比老版的高,如下是我做的 chart-JDK1.5importjava.awt.Color;importjava.awt.Font;importjava.io.File;importjava.io.FileOutputStream;importjava.text.DecimalFormat;importjava.text.NumberFormat;importorg.j.chart.ChartFactory;importorg.j.chart.ChartUtilities;importorg.j.chart.JChart;importorg.jimportorg.j.chart.axis.CategoryLabelPositions;importorg.j.chart.axis.NumberAxis;importorg.jimportorg.j.chart.labels.StandardCategoryItemLabelGenerator;importorg.j.chart.labels.StandardPieSectionLabelGenerator;importorg.j.chart.plot.CategoryPlot;importorg.j.chart.plot.PiePlot3D;importorg.j.chart.plot.PlotOrientation;importorg.jimportorg.j.chart.renderer.category.LineAndShapeRenderer;importorg.j importorg.j importorg.j.data.category.CategoryDataset;importorg.j.data.general.DatasetUtilities;importorg.j.data.general.DefaultPieDataset;importorg.j.data.general.PieDataset;*@authorpublicclass{publicstaticvoidmain(String[]{//TODOAuto-generatedmethodstubCreateChartServiceImplpm=newCreateChartServiceImpl();//////////}publicvoid{double[][]data=new{{672,766,223,540,126{325,521,210,340,106{332,256,523,240,526}String[]rowKeys苹果梨子葡萄String[]columnKeys={"","","广州","",""CategoryDatasetdataset=getBarData(data,rowKeys,columnKeys);createTimeXYChar("折线图x轴y轴dataset"lineAndShap.png");}publicvoid{double[][]data=new{{672,766,223,540,126{325,521,210,340,106{332,256,523,240,526}String[]rowKeys苹果梨子葡萄String[]columnKeys={"","","广州","",""CategoryDatasetdataset=getBarData(data,rowKeys,columnKeys);createBarChart(datasetx坐标y坐标柱状图barGroup.png");}publicvoid{double[][]data=new{{672,766,223,540,126}String[]rowKeys{"苹果String[]columnKeys{"","","广州","",""CategoryDatasetdatasetgetBarData(datarowKeys,columnKeys);createBarChart(dataset,"x坐标","y坐标","柱状图","bar.png");}publicvoid{double[][]data=new{{0.21,0.66,0.23,0.40,0.26{0.25,0.21,0.10,0.40,0.16}String[]rowKeys{"苹果","梨子"};StringcolumnKeys{"","","广州","",""CategoryDatasetdataset=getBarData(data,rowKeys,columnKeys);createStackedBarChart(datasetx坐标y坐标柱状图"stsckedBar.png");}publicvoid{double[]data{9,91String[]keys失败率成功率parePimChar(getDataPieSetByUtil(datakeys),饼状图","pie2.png",keys);}//柱状图,publicCategoryDatasetgetBarData(double[][]data,String[]rowKeys,String[]columnKeys){return}//publicPieDatasetgetDataPieSetByUtil(double[]data,String[]datadescription){if(data!=null&&datadescription!={if(data.length=={DefaultPieDatasetdataset=newDefaultPieDataset();for(inti=0;i<data.length;i++){}return}}return}*@paramdataset@paramxNamex轴的说明(如种类,时间等@paramyNamey轴的说明(如速度,时间等@paramchartTitle@paramcharName生成的名publicStringcreateBarChart(CategoryDatasetdataset,StringxName,StringyName,StringchartTitle,StringcharName){ ChartchartChartFactory.createBarChart(chartTitle,//xName,//轴的显示yName数值轴的显示dataset,//数据集PlotOrientation.VERTICAL,图表方向:水平、垂直true是否显示图例(对于简单的柱状图必须是false)false,//是否生成工具false//URLFontlabelFont=newFont("SansSerif",Font.TRUETYPE_FONT,//createCategoryPlotplot=//////NumberAxisvn=(NumberAxis)//DecimalFormatdf=newDecimalFormat("#0.00");vn.setNumberFormatOverride(df);//数据轴数据的显示格式x Axis=plot.getAxis();Axis.setLabelFont(labelFont);//轴标题Axis.setTickLabelFont(labelFont);//轴数值// //.createUpRotationLabelPositions(Math.PI/ umCategoryLabelWidthRatio(0.6f);//Lable//设置距离左端距//设置距离右端距//columnKey //设置柱图背景色(16位的模式来查看颜色编码,这样比较plot.setBackgroundPaint(newColor(255,255,yValueAxisrangeAxis=plot.getRangeAxis();//设置最高的一个Item与顶端的距//设置最低的一个Item与底端的距离BarRendererrenderer=new////////////renderer.setSeriesPaint(0,newColor(204,255,renderer.setSeriesPaint(1,newColor(153,204,renderer.setSeriesPaint(2,newColor(51,204,////.setBaseItemLabelGenerator(newStandardCategoryItemLabelGenerator());//设置柱的FileOutputStreamfos_jpg=null;{StringchartName=CHART_PATH+charName;fos_jpg=newFileOutputStream(chartName);ChartUtilities.writeChartAsPNG(fos_jpg,chart,500,500,true,10);returnchartName;}catch(Exception{returnnull;}{{}catch(Exception{}}}@paramdataset@paramxNamex轴的说明(如种类,时间等@paramyNamey轴的说明(如速度,时间等@paramchartTitle@paramcharName生成的名publicStringcreateHorizontalBarChart(CategoryDatasetdataset,StringxName,StringyName,StringchartTitle,StringcharName){ ChartchartChartFactory.createBarChart(chartTitle,//xName,//轴的显示yName数值轴的显示dataset,//数据集PlotOrientation.VERTICAL,图表方向:水平、垂直true是否显示图例(对于简单的柱状图必须是false)false,//是否生成工具false//URLCategoryPlotplot=//NumberAxisvn=(NumberAxis)//0//vn.setAutoRangeIncludesZero(true);DecimalFormatdf=newDecimalFormat("#0.00");vn.setNumberFormatOverride(df);//数据轴数据的显示格 Axis=plot.getAxis();Axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);//横轴上的//FontlabelFont=newFont("SansSerif",Font.TRUETYPE_FONT,Axis.setLabelFont(labelFont);//Axis.setumCategoryLabelWidthRatio(0.8f);//横轴上的Lable是否完整显// ValueAxisrangeAxis=//设置最高的一个Item与顶端的距//设置最低的一个Item与底端的距离BarRendererrenderer=new// ////renderer.setSeriesPaint(0,Color.GREEN);renderer.setSeriesPaint(1,newColor(0,0,255));////////设置柱的FileOutputStreamfos_jpg=null;{StringchartName=CHART_PATH+charName;fos_jpg=newFileOutputStream(chartName);ChartUtilities.writeChartAsPNG(fos_jpg,chart,500,500,true,10);returnchartName;}catch(Exception{returnnull;}{{}catch(Exception{}}}@paramdataset@paramchartTitle@paramcharName@parampieKeyspublicString parePimChar(PieDatasetdataset,StringchartTitle,StringcharName,String[]pieKeys){ //titledataset,//datatrue,//includelegendtrue,false);//使下说明字体清晰,去锯齿类似//背景//FontfontnewFont("隶书Font.BOLD25);TextTitletitle=newTextTitle(chartTitle);PiePlot3Dplot=(PiePlot3D)//中显示百分比:默认方////////////中显示百分比:自定义方式,{0}表示选项,{1}表示数值,{2}表示所占比例plot.setLabelGenerator(newStandardPieSectionLabelGenerator("{0}={1}({2})",NumberFormat.getNumberInstance(),newDecimalFormat("0.00%")));//图例显示百分比:{0}{1}{2}plot.setLegendLabelGenerator(newStandardPieSectionLabelGenerator(//指定的(0.0-1.0)//指定显示的饼图上圆形(false)还椭圆形(true)plot.setCircular(false,true);//section12////plot.setSectionPaint(pieKeys[0],newColor(244,194,plot.setSectionPaint(pieKeys[1],newColor(144,233,FileOutputStreamfos_jpg=null;{//StringchartName=CHART_PATH+charName;fos_jpg=newFileOutputStream(chartName);//的设置影响椭圆饼图的形return}catch(Exception{returnnull;}{{System.out.println("createpie-chart.");}catch(Exception{}}}@paramprivatevoidisChartPathExist(String{Filefile=newFile(chartPath);if(!file.exists()){//}}@param@param@param@param@parampublicStringcreateTimeXYChar(StringchartTitle,Stringx,Stringy,CategoryDatasetxyDataset,StringcharName){ Chartchart=ChartFactory.crea ineChart(chartTitle,x,y,xyDataset,PlotOrientation.VERTICAL,true,true,false);//FontfontnewFont("隶书Font.BOLD25);TextTitletitle=newTextTitle(chartTitle);//FontlabelFont=newFont("SansSerif",Font.TRUETYPE_FONT,12);CategoryPlotcategoryplot=(CategoryPlot)x////y轴//数据轴网格是否可见categoryplot.setRangeGridlinePaint(Color.WHITE);//虚线色彩 GridlinePaint(Color.WHITE);//虚线色彩////categoryplot.setAxisOffset(newRectangleInsets(5D,5D,5D,CategoryAxisAxis=categoryplot.getAxis();Axis.setLabelFont(labelFont);//轴标题);////45//设置距离左端距//设置距离右端距NumberAxisnumberaxis=(NumberAxis)categoryplot.getRangeAxis();//rendererlineandshaperendererLineAndShapeRendererlineandshaperendererLineAndShapeRenderercategoryplot);//);//////////FileOutputStreamfos_jpg=null;{StringchartName=CHART_PATH+charName;fos_jpg=newFileOutputStream(chartName);//将报表保存为pngreturn}catch(Exception{returnnull;}{{}catch(Exception{}}}@param@param@param@param@parampublicStringcreateStackedBarChart(CategoryDatasetdataset,StringxName,StringyName,StringchartTitle,StringcharName){1://2:JChart对JChartchartChartFactory.createStackedBarChart(chartTitle,//xName,//轴的显示yName数值轴的显示dataset,//数据集PlotOrientation.VERTICAL,图表方向:水平、垂直true是否显示图例(false)false,//是否生成工具false//URL//2.2TextTitle,2.2.1:x,yFontlabelFont=newFont("SansSerif",Font.TRUETYPE_FONT,2.3PlotPlotCategoryPlotplot=//////NumberAxisvn=(NumberAxis)//1//

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论