×

jfreechart饼图 li 饼图

jfreechart饼图(myeclipse中如何用jfreechart制作饼图)

admin admin 发表于2023-05-25 05:34:22 浏览46 评论0

抢沙发发表评论

本文目录

myeclipse中如何用jfreechart制作饼图

给你个比较简单的application版本的饼图
package com.test.jfreechart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;
publicclass JFreeChartTest
{
publicstaticvoid main(String args)
{
DefaultPieDataset dpd=new DefaultPieDataset(); //建立一个默认的饼图
dpd.setValue(“管理人员“, 25); //输入数据
dpd.setValue(“市场人员“, 25);
dpd.setValue(“开发人员“, 45);
dpd.setValue(“其他人员“, 10);
JFreeChart chart=ChartFactory.createPieChart(“某公司人员组织数据图“,dpd,true,true,false);
//可以查具体的API文档,第一个参数是标题,第二个参数是一个数据集,第三个参数表示是否显示Legend,第四个参数表示是否显示提示,第五个参数表示图中是否存在URL
ChartFrame chartFrame=new ChartFrame(“某公司人员组织数据图“,chart);
//chart要放在Java容器组件中,ChartFrame继承自java的Jframe类。该第一个参数的数据是放在窗口左上角的,不是正中间的标题。
chartFrame.pack(); //以合适的大小展现图形
chartFrame.setVisible(true);//图形是否可见
}}

JFreeChart 输出饼图问题

我试了一下,piechart生成正常的,楼主看不到可能只不过没有输出而已。
和bar图一样在jsp里ChartFacotory生成chart后,添上向response里输出pie图字节流的语句即可:
ChartUtilities.writeChartAsPNG(response.getOutputStream(),chart,500,300);

jfreechart 如何在饼图内 显示百分比

// 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位
plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
“{0}={1}辆({2})“, NumberFormat.getNumberInstance(),
new DecimalFormat(“0.00%“)));

关于jfreechart饼状图

随便几句话是说不清的。推荐你看风中叶的struts2视频(到电驴上面搜下),大概到第二十几讲是关于jfreechart的。不过我做他的实验时有乱码,下面附上jfreechart的流程和乱码解决方案。
创建一个数据源(dataset)来包含将要在图形中显示的数据
》》创建一个 JFreeChart 对象来代表要显示的图形
》》把图形输出
重要的类和接口:
org.jfree.data.general.Dataset 所有数据源类都要实现的接口
org.jfree.chart.ChartFactory 由它来产生 JFreeChart 对象
org.jfree.chart.JFreeChart 所有对图形的调整都是通过它噢!!
org.jfree.chart.plot.Plot 通过JFreeChart 对象获得它,然后再通过它对图形外部部分(例:坐标轴)调整
注意:它有很多子类,一般都下嗍造型到它的子类!
org.jfree.chart.renderer.AbstractRenderer 通过JFreeChart 对象获得它,然后再通过它对图形内部部分
(例:折线的类型)调整。同样,针对不同类型的报表图,它有
着不同的子类实现!
jfreechart中文乱码问题解决方案(转)
柱状图(CategoryPlot):
CategoryPlot plot=chart.getCategoryPlot();//获取图表区域对象
CategoryAxis domainAxis=plot.getDomainAxis();
//水平底部列表
domainAxis.setLabelFont(new Font(“黑体“,Font.BOLD,14));
//水平底部标题
domainAxis.setTickLabelFont(new Font(“宋体“,Font.BOLD,12));
//垂直标题
ValueAxis rangeAxis=plot.getRangeAxis();//获取柱状
rangeAxis.setLabelFont(new Font(“黑体“,Font.BOLD,15));
chart.getLegend().setItemFont(new Font(“黑体“, Font.BOLD, 15));
饼图(PiePlot):
JFreeChart chart = ChartFactory.createPieChart3D(“IT行业职业分布图“, dataset, true, false, false);
chart.getTitle().setFont(new Font(“黑体“,Font.BOLD,20));//设置标题字体
PiePlot piePlot= (PiePlot) chart.getPlot();//获取图表区域对象
piePlot.setLabelFont(new Font(“黑体“,Font.BOLD,10));
chart.getLegend().setItemFont(new Font(“黑体“,Font.BOLD,10));
时序图(TimeSeries)
XYPlot plot = (XYPlot) chart.getPlot();
//纵轴字体
plot.getRangeAxis().setLabelFont(new Font(“宋体“, Font.BOLD, 15));
//横轴框里的标题字体
chart.getLegend().setItemFont(new Font(“宋体“, Font.ITALIC, 15));
//横轴列表字体
plot.getDomainAxis().setTickLabelFont(new Font(“新宋体“, 1, 15));
//横轴小标题字体
plot.getDomainAxis().setLabelFont(new Font(“新宋体“, 1, 12));
折线图
chart.getTitle().setFont(new Font(“宋体“, Font.BOLD, 15));
chart.getLegend().setItemFont(new Font(“黑体“, Font.BOLD, 15));
CategoryAxis domainAxis = plot.getDomainAxis();
/*------设置X轴坐标上的文字-----------*/
domainAxis.setTickLabelFont(new Font(“黑体“, Font.PLAIN, 11));
/*------设置X轴的标题文字------------*/
domainAxis.setLabelFont(new Font(“宋体“, Font.PLAIN, 12));
NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();
/*------设置Y轴坐标上的文字-----------*/
numberaxis.setTickLabelFont(new Font(“黑体“, Font.PLAIN, 12));

/*------设置Y轴的标题文字------------*/
numberaxis.setLabelFont(new Font(“黑体“, Font.PLAIN, 12))

jfreechart 3D饼图标签分散开排列的问题

我个人认为如果项目比较多,不如做成
柱状图
,如果非要做成
饼图
的话
,不妨把比率比较小的合成一个“其他”。对统计学研究不多,
献丑

使用JFreeChart生成多饼图时,怎么设置其布局

createMultiplePieChart这个方法生成的多个图是可以布局的,但是他是你dataset.addValue()有几个他就生成几个图。而且都是一样的。
用java图形用户界面来做那就用java的布局管理器类来做如下:
JPanel panel = new JPanel(new GridLayout(2, 2));
//new GridLayout(2, 2)网格型的布局处理器,就是把容器被分成大小相等的矩形,一个矩形中放置一个组件。这是个2行*2列的布局
DefaultCategoryDataset dataset=new DefaultCategoryDataset();
dataset.addValue(23.3, “Section 1“, “Section“);
dataset.addValue(56.5, “Section 2“, “Section“);
dataset.addValue(43.3, “Section 3“, “Section“);
dataset.addValue(11.1, “Section 4“, “Section“);
JFreeChart chart1 = ChartFactory.createMultiplePieChart(“Multiple Pie Chart“, dataset,TableOrder.BY_ROW,
true,true, false );
panel.add(new ChartPanel(chart1));
panel.setPreferredSize(new Dimension(800, 600));//设置整个画布的大小
这样你生成的图就会是2行*2列的,要其他的只要改new GridLayout(2, 2)这个就好了。还有其他多种布局方式,如FlowLayout,BorderLayout

jfreechart生成饼状图显示数据的百分比

JFreeChart chart =null;
PiePlot pieplot = (PiePlot) chart.getPlot();//获取图片对象
// 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位
piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator(
“{0}({2})“, NumberFormat.getNumberInstance(),
new DecimalFormat(“0.00%“)));

以上为关键代码。需要通过setLableGenerator方法设置标签显示格式。StandardPieSectionLabelGenerator对象构造方法中,{0},{2}都将被替换为相应字符,{0}显示的是花生、大豆等信息,{2}显示的是百分比,后面两个参数是设置百分比格式,可以不设置,默认不保留小数点。最后图表显示的信息为:花生(xx.xx%)  小麦(xx.xx%)。

图下面的描述也可以设置显示格式,关键代码为:

// 图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例
piePlot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
“{0} ({2})“));

注意,这是setLegendLableGenerator()。可以多试试new StandardPieSectionLabelGenerator(“{0} ({2})“)里的参数设置。