JfreeChar柱状图实例

本文深入探讨了为何80%的码农未能成为架构师,从技能、思维模式和职业路径三个角度剖析原因,并提供了成为优秀架构师的建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package com.test;

import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
import org.jfree.*;

public class PieChartPicture {
 public static void main(String[] args) {
  
  //这里是获取SQL查询得到的数据
  PieDataset dataset = getDataSet();
  
  JFreeChart chart = ChartFactory.createPieChart3D(" 项目进度分布", // chart
                 // title
    dataset,// data
    true,// include legend
    true, false);
  PiePlot3D plot = (PiePlot3D) chart.getPlot();
  // 图片中显示百分比:默认方式
  // plot.setLabelGenerator(new
  // StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT));
  // 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位
  plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
    "{0}={1}({2})", NumberFormat.getNumberInstance(),
    new DecimalFormat("0.00%")));
  // 图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例
  plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
    "{0}={1}({2})"));
  // 设置背景色为白色
  chart.setBackgroundPaint(Color.white);
  // 指定图片的透明度(0.0-1.0)
  plot.setForegroundAlpha(1.0f);
  // 指定显示的饼图上圆形(false)还椭圆形(true)
  plot.setCircular(true);
  // 设置图标题的字体
  Font font = new Font(" 黑体", Font.CENTER_BASELINE, 20);
  TextTitle title = new TextTitle(" 项目状态分布");
  title.setFont(font);
  chart.setTitle(title);
  FileOutputStream fos_jpg = null;
  try {
   fos_jpg = new FileOutputStream("D:\\ 项目状态分布.jpg");
//可以讲图返回给前台使用
ChartUtilities
     .writeChartAsJPEG(fos_jpg, 100, chart, 640, 480, null);
   fos_jpg.close();
  } catch (Exception e) {
  }
 }

}

 

转载于:https://my.oschina.net/barter/blog/97186

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值