java图形报表-3(柱状图)

public class DIYzhuzhuangtu {

 public static void main(String[] args) {
 
  String title = "柱状图测试";
  String domain = "单位比较";
  String range = "数值";
  /**
   * 初始化数据
   */

  DefaultCategoryDataset data = new DefaultCategoryDataset();
  for (int r = 0; r < 5; r++) {
  String rowKey = "单位 [" + (r + 1)+"]" ;

  for (int c = 0; c < 4; c++) {

  String columnKey = "2006年" + (c + 1) + "月";
  data.addValue(new Double(r * c + 3), rowKey, columnKey);
  }
  }
  /**
   * 建立JFreeChart对象
   */
JFreeChart chart=
   ChartFactory.createBarChart(
   title,
   domain,
   range,
   data,
   PlotOrientation.VERTICAL,
   true,
   true,
   false);
/**
 * 设置背景颜色和大小
 */
  chart.setBackgroundPaint(
  new GradientPaint(0, 0, Color.white, 1000, 0, Color.red));
  chart.setTitle(new TextTitle(title, new Font("隶书", Font.ITALIC, 15)));
  CategoryPlot plot = (CategoryPlot)chart.getPlot();
  /**
   * 设置字体
   */
  plot.setForegroundAlpha(0.9f);
//  plot.setValueLabelFont(new Font("黑体", Font.TRUETYPE_FONT, 12));
//  plot.setSectionLabelFont(new Font("黑体", Font.TRUETYPE_FONT, 12));
//  注意以下代码
  NumberAxis verticalAxis = (NumberAxis)plot.getRangeAxis();
  verticalAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//   输出文件到指定目录
  long time=new Date().getTime();
  String rfname = "Pie_"+time+ ".jpeg";
  String fileName = "d:\\" + rfname;
  try {
  ChartUtilities.saveChartAsJPEG(new File(fileName), 100, chart, 600, 600);
//   log.info("....Create image File:" + fileName);
  } catch (IOException exz) {
   System.out.print("不能创建JPEG图片! 可能是文件的路径不正确");
  }
 System.out.println("输出保存在D://中 Pie_"+time+".jpeg");
 }
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值