欢迎来到天天文库
浏览记录
ID:37511826
大小:236.50 KB
页数:13页
时间:2019-05-24
《jfreechart实现java画图》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、packagecom.dsc.utils;importjava.awt.Color;importjava.awt.Font;importjava.awt.RenderingHints;importjava.io.File;importjava.io.IOException;importorg.jfree.chart.ChartFactory;importorg.jfree.chart.ChartUtilities;importorg.jfree.chart.JFreeChart;importorg.jfree.chart.axis.NumberAxis;i
2、mportorg.jfree.chart.axis.ValueAxis;importorg.jfree.chart.labels.StandardXYItemLabelGenerator;importorg.jfree.chart.plot.PlotOrientation;importorg.jfree.chart.plot.XYPlot;importorg.jfree.chart.renderer.xy.XYLineAndShapeRenderer;importorg.jfree.chart.title.TextTitle;importorg.jfree
3、.data.xy.XYSeries;importorg.jfree.data.xy.XYSeriesCollection;importorg.jfree.ui.RectangleInsets;publicclassJfreeChartUtils_Line{/***@parampictureTitle图表标题*@paramxTitlex轴标题*@paramyTitley轴标题*@paramdataset数据集*@paramwidth宽度*@paramheight高度*@return图片的路径*/publicStringcreateLinePicture(St
4、ringpictureTitle,StringxTitle,StringyTitle,XYSeriesCollectiondataset,intwidth,intheight){Stringpath="";JFreeChartchart=ChartFactory.createXYLineChart(pictureTitle,yTitle,xTitle,dataset,PlotOrientation.VERTICAL,true,true,false);chart.setBackgroundPaint(Color.LIGHT_GRAY);//设置图表属性//取
5、得CategoryPlot,设定Plot参数XYPlotplot=chart.getXYPlot();//设置网格背景颜色plot.setBackgroundPaint(Color.white);//设置网格竖线颜色plot.setDomainGridlinePaint(Color.pink);//设置网格横线颜色plot.setRangeGridlinePaint(Color.pink);//设置是否显示垂直网格线plot.setDomainGridlinesVisible(true);//设置是否显示水平网格线plot.setRangeGridline
6、sVisible(true);XYLineAndShapeRendererxylineandshaperenderer=(XYLineAndShapeRenderer)plot.getRenderer();//设置曲线图与xy轴的距离plot.setAxisOffset(newRectangleInsets(0D,0D,0D,10D));//设置曲线是否显示数据点xylineandshaperenderer.setItemLabelGenerator(newStandardXYItemLabelGenerator());xylineandshaperend
7、erer.setBaseShapesVisible(true);//是否显示数据点的值xylineandshaperenderer.setBaseItemLabelsVisible(true);//X轴整数显示NumberAxisx=(NumberAxis)plot.getDomainAxis();x.setStandardTickUnits(NumberAxis.createIntegerTickUnits());//Y轴整数显示NumberAxisy=(NumberAxis)plot.getDomainAxis();y.setStandardTickU
8、nits(NumberAxis.createIntegerTick
此文档下载收益归作者所有