jfreechart饼状图示例

public static void main(String[] args) 
{
    //创建主题样式 ,以下代码用于解决中文乱码问题
    StandardChartTheme standardChartTheme=new StandardChartTheme("CN");  
    //设置标题字体  
    standardChartTheme.setExtraLargeFont(new Font("宋体",Font.BOLD,20));  
    //设置图例的字体  
    standardChartTheme.setRegularFont(new Font("宋体",Font.PLAIN,15));  
    //设置轴向的字体  
    standardChartTheme.setLargeFont(new Font("宋体",Font.PLAIN,15));  
    //应用主题样式  
    ChartFactory.setChartTheme(standardChartTheme);

    //数据源
    DefaultPieDataset dataset = new DefaultPieDataset();   
    dataset.setValue("数据库", 21);   
    dataset.setValue("中间件", 33);   
    dataset.setValue("主机", 43);

    //创建图
    JFreeChart chart=ChartFactory.createPieChart3D("设备分布图", dataset,
              true,true,Locale.getDefault());

    PiePlot3D pieplot = (PiePlot3D) chart.getPlot(); 

    //设置画布颜色为白色
    pieplot.setBackgroundPaint(SystemColor.WHITE); 

    //设置旋转角度    
    pieplot.setStartAngle(180.0);    
    
    //设置旋转方向,Rotation.CLOCKWISE)为顺时针。    
    pieplot.setDirection(Rotation.CLOCKWISE);    

    //设置图表透明图0.0~1.0范围。0.0为完全透明,1.0为完全不透明。    
    pieplot.setForegroundAlpha(0.7F);  

    //无数据时的提示信息
    pieplot.setNoDataMessage("No data to display");  

    //个性化设置饼图描述{0}指标名,{1}数量,{2}占比
    pieplot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{2}"
         ,NumberFormat.getNumberInstance(),new DecimalFormat("0.0%")));

    //设置label的背景色为白色
    pieplot.setLabelBackgroundPaint(SystemColor.WHITE);

    ChartFrame chartFrame=new ChartFrame("设备分布图",chart);   

    //以合适的大小展现图形  
    chartFrame.pack();

    //图形是否可见
    chartFrame.setVisible(true);
}

效果图如下:


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值