jfreechart线图柱图饼图散点图Word文档格式.docx
- 文档编号:7278382
- 上传时间:2023-05-08
- 格式:DOCX
- 页数:42
- 大小:22.72KB
jfreechart线图柱图饼图散点图Word文档格式.docx
《jfreechart线图柱图饼图散点图Word文档格式.docx》由会员分享,可在线阅读,更多相关《jfreechart线图柱图饼图散点图Word文档格式.docx(42页珍藏版)》请在冰点文库上搜索。
*/
publicvoidcreateLineChart(){
//设置数据
cddata=newDefaultCategoryDataset();
for(inti=0;
i<
datas.length;
i++){
if(datas[i].length==0){
cddata.setValue(null,"
"
categoryKeys[i]);
}else{
for(intj=0;
j<
datas[i].length;
j++){
cddata.setValue(datas[i][j],descriptionKeys[j],categoryKeys[i]);
}
}
}
/**数据
System.out.println("
**************************datasbegin:
**************************"
);
for(intj=0;
System.out.println(categoryKeys[i]+"
:
"
+descriptionKeys[j]+"
|"
+datas[i][j]);
}
**************************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;
descriptionKeys.length;
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.setNoDataMessage("
没有数据!
plot.setLabelGenerator(newStandardPieSectionLabelGenerator(
("
{0}:
({2})"
),
NumberFormat.getNumberInstance(),
newDecimalFormat("
0.00%"
)));
PieChart"
publicvoidcreatePieChartValue(Double[]value){
dpdata.setValue(descriptionKeys[i],value[i]);
plot.setLabelGenerator(null);
plot.setToolTipGenerator(newStandardPieToolTipGenerator(("
{0}"
LegendTitlelegend=chart.getLegend();
legend.setBackgroundPaint(newColor(238,244,255));
//图例背景
legend.setItemFont(newFont("
宋体"
Font.ITALIC,12));
//图例的字体
legend.setPosition(RectangleEdge.RIGHT);
//图例位置
legend.setHeight(1000.00);
*柱图
publicvoidcreateBarChart(){
chart=ChartFactory.createBarChart(title,//图表标题
cddata,//数据集
水平、垂直
true,//是否显示图例(对于简单的柱状图必须是false)
true,//是否生成工具
false//是否生成URL
);
//设置图表的颜色
publicvoidcreateBarChart3D(Object[]data){
data.length;
cddata.setValue((Number)data[i],categoryKeys[i],categoryKeys[i]);
chart=ChartFactory.createBarChart3D(title,//图表标题
*对比柱状图
publicvoidcreateBarChart(CategoryDatasetdataset){
dataset,//数据集
*面积图
publicvoidcreateAreaChart(){
chart=ChartFactory.createAreaChart(title,//图表标题
*X,Y线图chart
*paramchartMap
*/
publicvoidcreateXYLineChart(Map<
String,Map<
Double,Double>
>
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);
XYChart"
*双y轴曲线图,没有折线点
*paramcddata
publicvoidcreateXYsLineChart(DefaultCategoryDatasetcddataLeft,DefaultCategoryDatasetcddataRight){
//设置字体样式
Fontfs=newFont("
微软雅黑"
Font.BOLD,12);
Fontf=newFont("
Font.PLAIN,12);
chart=ChartFactory.createLineChart(title,//标题
cddataLeft,//dataset
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.setSeriesStroke(0,newBasicStroke(1.6F));
//y轴(右边),绘制单元对象LineAndShapeRenderer
LineAnd
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- jfreechart 线图 柱图饼图散点图