jfreechart 线图 柱图 饼图 散点图.docx

上传人:b****2 文档编号:2412687 上传时间:2023-05-03 格式:DOCX 页数:42 大小:22.75KB
下载 相关 举报
jfreechart 线图 柱图 饼图 散点图.docx_第1页
第1页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第2页
第2页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第3页
第3页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第4页
第4页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第5页
第5页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第6页
第6页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第7页
第7页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第8页
第8页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第9页
第9页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第10页
第10页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第11页
第11页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第12页
第12页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第13页
第13页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第14页
第14页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第15页
第15页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第16页
第16页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第17页
第17页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第18页
第18页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第19页
第19页 / 共42页
jfreechart 线图 柱图 饼图 散点图.docx_第20页
第20页 / 共42页
亲,该文档总共42页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

jfreechart 线图 柱图 饼图 散点图.docx

《jfreechart 线图 柱图 饼图 散点图.docx》由会员分享,可在线阅读,更多相关《jfreechart 线图 柱图 饼图 散点图.docx(42页珍藏版)》请在冰点文库上搜索。

jfreechart 线图 柱图 饼图 散点图.docx

jfreechart线图柱图饼图散点图

publicabstractclassChartActionextendsBaseAction{

publicJFreeChartchart;

privateString[]descriptionKeys;

privateString[]categoryKeys;

privateDouble[][]datas;

privateDefaultCategoryDatasetcddata;

privateDefaultPieDatasetdpdata;

privateXYDatasetxydata;

privateIntervalXYDatasetixydata;

privateStringtitle;//标题

privateStringx;//横坐标名称

privateStringy;//纵坐标名称

privateStringy2;//纵坐标名称2

/**

*线图

*/

publicvoidcreateLineChart(){

//设置数据

cddata=newDefaultCategoryDataset();

for(inti=0;i

if(datas[i].length==0){

cddata.setValue(null,"",categoryKeys[i]);

}else{

for(intj=0;j

cddata.setValue(datas[i][j],descriptionKeys[j],categoryKeys[i]);

}

}

}

/**数据

System.out.println("**************************datasbegin:

**************************");

for(inti=0;i

for(intj=0;j

System.out.println(categoryKeys[i]+":

"+descriptionKeys[j]+"|"+datas[i][j]);

}

}

System.out.println("**************************datasend:

****************************");

*/

chart=ChartFactory.createLineChart(title,//图表标题

x,//目录轴的显示标签

y,//数值轴的显示标签

cddata,//数据集

PlotOrientation.VERTICAL,//图表方向:

水平、垂直

true,//是否显示图例(对于简单的柱状图必须是false)

true,//是否生成工具

false);//是否生成URL链接

CategoryPlotplot=chart.getCategoryPlot();

plot.setBackgroundPaint(newColor(238,244,255));//设置图表的颜色

plot.setDomainGridlinePaint(Color.lightGray);//设置垂直网格线的颜色

plot.setRangeGridlinePaint(Color.lightGray);//设置水平网格线的颜色

plot.setDomainGridlinesVisible(true);//设置垂直网格线是否显示

plot.setRangeGridlinesVisible(true);//设置水平网格线是否显示

LineAndShapeRendererlineandshaperenderer=(LineAndShapeRenderer)plot.getRenderer();

lineandshaperenderer.setBaseShapesVisible(true);

lineandshaperenderer.setBaseShapesFilled(true);

chart.setBackgroundPaint(Color.white);

setChartFont("");

}

/**

*饼图

*/

publicvoidcreatePieChart(){

dpdata=newDefaultPieDataset();

//生成JFreeChart对象

Doubled=0.0;

for(inti=0;i

for(intj=0;j

d=d+(datas[j][i]==null?

0:

datas[j][i]);

}

dpdata.setValue(descriptionKeys[i],d.doubleValue());

}

chart=ChartFactory.createPieChart(title,dpdata,true,true,true);

PiePlotplot=(PiePlot)chart.getPlot();

plot.setBackgroundPaint(newColor(238,244,255));//设置图表的颜色

plot.setNoDataMessage("没有数据!

");

plot.setLabelGenerator(newStandardPieSectionLabelGenerator(

("{0}:

({2})"),

NumberFormat.getNumberInstance(),

newDecimalFormat("0.00%")));

chart.setBackgroundPaint(Color.white);

setChartFont("PieChart");

}

/**

*饼图

*/

publicvoidcreatePieChartValue(Double[]value){

dpdata=newDefaultPieDataset();

//生成JFreeChart对象

for(inti=0;i

dpdata.setValue(descriptionKeys[i],value[i]);

}

chart=ChartFactory.createPieChart(title,dpdata,true,true,true);

PiePlotplot=(PiePlot)chart.getPlot();

plot.setBackgroundPaint(newColor(238,244,255));//设置图表的颜色

plot.setNoDataMessage("没有数据!

");

plot.setLabelGenerator(null);

plot.setToolTipGenerator(newStandardPieToolTipGenerator(("{0}"),

NumberFormat.getNumberInstance(),

newDecimalFormat("0.00%")));

LegendTitlelegend=chart.getLegend();

legend.setBackgroundPaint(newColor(238,244,255));//图例背景

legend.setItemFont(newFont("宋体",Font.ITALIC,12));//图例的字体

legend.setPosition(RectangleEdge.RIGHT);//图例位置

legend.setHeight(1000.00);

chart.setBackgroundPaint(Color.white);

setChartFont("PieChart");

}

/**

*柱图

*/

publicvoidcreateBarChart(){

//设置数据

cddata=newDefaultCategoryDataset();

for(inti=0;i

if(datas[i].length==0){

cddata.setValue(null,"",categoryKeys[i]);

}else{

for(intj=0;j

cddata.setValue(datas[i][j],descriptionKeys[j],categoryKeys[i]);

}

}

}

chart=ChartFactory.createBarChart(title,//图表标题

x,//目录轴的显示标签

y,//数值轴的显示标签

cddata,//数据集

PlotOrientation.VERTICAL,//图表方向:

水平、垂直

true,//是否显示图例(对于简单的柱状图必须是false)

true,//是否生成工具

false//是否生成URL链接

);

CategoryPlotplot=chart.getCategoryPlot();

plot.setBackgroundPaint(newColor(238,244,255));//设置图表的颜色

chart.setBackgroundPaint(Color.white);

setChartFont("");

}

/**

*柱图

*/

publicvoidcreateBarChart3D(Object[]data){

//设置数据

cddata=newDefaultCategoryDataset();

for(inti=0;i

cddata.setValue((Number)data[i],categoryKeys[i],categoryKeys[i]);

}

chart=ChartFactory.createBarChart3D(title,//图表标题

x,//目录轴的显示标签

y,//数值轴的显示标签

cddata,//数据集

PlotOrientation.VERTICAL,//图表方向:

水平、垂直

true,//是否显示图例(对于简单的柱状图必须是false)

true,//是否生成工具

false//是否生成URL链接

);

CategoryPlotplot=chart.getCategoryPlot();

plot.setBackgroundPaint(newColor(238,244,255));//设置图表的颜色

chart.setBackgroundPaint(Color.white);

setChartFont("");

}

/**

*对比柱状图

*/

publicvoidcreateBarChart(CategoryDatasetdataset){

chart=ChartFactory.createBarChart(title,//图表标题

x,//目录轴的显示标签

y,//数值轴的显示标签

dataset,//数据集

PlotOrientation.VERTICAL,//图表方向:

水平、垂直

true,//是否显示图例(对于简单的柱状图必须是false)

true,//是否生成工具

false//是否生成URL链接

);

CategoryPlotplot=chart.getCategoryPlot();

plot.setBackgroundPaint(newColor(238,244,255));//设置图表的颜色

chart.setBackgroundPaint(Color.white);

setChartFont("");

}

/**

*面积图

*/

publicvoidcreateAreaChart(){

//设置数据

cddata=newDefaultCategoryDataset();

cddata=newDefaultCategoryDataset();

for(inti=0;i

if(datas[i].length==0){

cddata.setValue(null,"",categoryKeys[i]);

}else{

for(intj=0;j

cddata.setValue(datas[i][j],descriptionKeys[j],categoryKeys[i]);

}

}

}

chart=ChartFactory.createAreaChart(title,//图表标题

x,//目录轴的显示标签

y,//数值轴的显示标签

cddata,//数据集

PlotOrientation.VERTICAL,//图表方向:

水平、垂直

true,//是否显示图例(对于简单的柱状图必须是false)

true,//是否生成工具

false//是否生成URL链接

);

CategoryPlotplot=chart.getCategoryPlot();

plot.setBackgroundPaint(newColor(238,244,255));//设置图表的颜色

chart.setBackgroundPaint(Color.white);

setChartFont("");

}

/**

*X,Y线图chart

*@paramchartMap

*/

publicvoidcreateXYLineChart(Map>chartMap){

//创建XYDataset对象(准备数据)

xydata=createXYDataset(chartMap);

//创建JFreeChart对象:

ChartFactory.createXYLineChart

chart=ChartFactory.createXYLineChart(title,//标题

x,//categoryAxisLabel(category轴,横轴,X轴标签)

y,//valueAxisLabel(value轴,纵轴,Y轴的标签)

xydata,//dataset

PlotOrientation.VERTICAL,

true,//legend

true,//tooltips

true);//URLs

//使用CategoryPlot设置各种参数。

以下设置可以省略。

XYPlotplot=(XYPlot)chart.getPlot();

//x轴整数显示

NumberAxisna=(NumberAxis)plot.getDomainAxis();

na.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

XYLineAndShapeRendererrenderer=(XYLineAndShapeRenderer)plot.getRenderer();

renderer.setBaseItemLabelsVisible(true);

renderer.setBaseShapesVisible(true);

renderer.setBaseShapesFilled(true);

plot.setRenderer(0,renderer);

plot.setBackgroundPaint(newColor(238,244,255));//设置图表的颜色

plot.setDomainGridlinePaint(Color.lightGray);//设置垂直网格线的颜色

plot.setRangeGridlinePaint(Color.lightGray);//设置水平网格线的颜色

plot.setDomainGridlinesVisible(true);//设置垂直网格线是否显示

plot.setRangeGridlinesVisible(true);//设置水平网格线是否显示

chart.setBackgroundPaint(Color.white);

setChartFont("XYChart");

}

/**

*双y轴曲线图,没有折线点

*@paramcddata

*/

publicvoidcreateXYsLineChart(DefaultCategoryDatasetcddataLeft,DefaultCategoryDatasetcddataRight){

//设置字体样式

Fontfs=newFont("微软雅黑",Font.BOLD,12);

Fontf=newFont("微软雅黑",Font.PLAIN,12);

//创建JFreeChart对象:

ChartFactory.createXYLineChart

chart=ChartFactory.createLineChart(title,//标题

x,//categoryAxisLabel(category轴,横轴,X轴标签)

y,//valueAxisLabel(value轴,纵轴,Y轴的标签)

cddataLeft,//dataset

PlotOrientation.VERTICAL,

true,//legend

true,//tooltips

true);//URLs

//使用CategoryPlot设置各种参数。

以下设置可以省略。

CategoryPlotplot=(CategoryPlot)chart.getPlot();

//设置X坐标的显示方式(默认水平)

CategoryAxiscategoryaxis=plot.getDomainAxis();

categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);

categoryaxis.setCategoryMargin(9);//分类轴边距

//左边y轴显示方式

//NumberAxisnumberaxis=(NumberAxis)plotxy.getRangeAxis();//y轴整数显示

NumberAxisnumberaxis=newNumberAxis(this.y);

numberaxis.setLabelFont(fs);

numberaxis.setTickLabelFont(f);

plot.setRangeAxis(0,numberaxis);

//右边y轴显示方式

NumberAxisnumberaxis2=newNumberAxis(this.y2);

numberaxis2.setLabelFont(fs);

numberaxis2.setTickLabelFont(f);

plot.setRangeAxis(1,numberaxis2);

plot.setDataset(1,cddataRight);

plot.mapDatasetToRangeAxis(1,1);

//y轴(左边)

LineAndShapeRendererrenderer=(LineAndShapeRenderer)plot.getRenderer();

renderer.setBaseItemLabelsVisible(true);

plot.setRenderer(0,renderer);

renderer.setSeriesStroke(0,newBasicStroke(1.6F));

//y轴(右边),绘制单元对象LineAndShapeRenderer

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2