JFreeChar_图表的基本用法

dataCount = BookAction.getDataCount();  // 取得读者数据表记录数的数量
  this.showData(dataCount); // 显示基本数据
  
  dataset = new DefaultCategoryDataset();
  for(int i=0; i<tableData.length; i++) {
   dataset.addValue(Integer.parseInt(tableData[i][0].toString()),
     tableData[i][1].toString(), "1");  // 添加结果集记录
  }

  JFreeChart chart = ChartFactory.createBarChart3D(
        "图书借阅统计",               // 标题
        "图书名称",                  // 横轴名称
        "借阅次数",                  // 纵轴名称
        dataset,                   // 数据
        PlotOrientation.VERTICAL,  // 使用垂直柱状图
        true,                      // 是否使用legend
        false,                     // 是否使用tooltip
        false                      // 是否使用url链接
        );
  chart.setTitle(new TextTitle("图书借阅统计", new Font("黑体", Font.PLAIN, 14))); // 设置柱形图标题及标题字体
  plot = (CategoryPlot) chart.getPlot(); // 获得图表,以进行更多属性设置 = (CategoryPlot) chart.getPlot(); // 获得图表,以进行更多属性设置
  leTitle = chart.getLegend(); // 取得图标中的图例
  this.configureChart(); // 配置图标样式

 

// 配置图标参数
 private void configureChart() {
  CategoryAxis cAxis = plot.getDomainAxis(); // 获得目录轴
  cAxis.setTickLabelFont(new Font("楷体_gb2312", Font.PLAIN, 12)); // 设置目录轴坐标上文字的字体
  cAxis.setLabelFont(new Font("华文楷体", Font.PLAIN, 12)); // 设置目录轴轴的标题文字的字体

  ValueAxis vAxis = plot.getRangeAxis(); // 获得数据轴
  vAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10)); // 设置数据轴坐标上的文字的字体
  vAxis.setLabelFont(new Font("华文楷体", Font.PLAIN, 13)); // 设置数据轴的标题文字的字体
  //vAxis.setLowerMargin(0.005);
  //vAxis.setLabelInsets(RectangleInsets.ZERO_INSETS);

  leTitle.setItemFont(new Font("楷体_gb2312", Font.PLAIN, 12)); //设置图例中文字的字体,要求createBarChart3D中的是否图例必须为true
  leTitle.setPadding(0.05, 0.05, 0.05, 0.05); // 设置图例内目录的间隔
  leTitle.setPosition(RectangleEdge.RIGHT);  // 设置图例在图表的显示区域
  // leTitle.setWidth(50);

  BarRenderer3D renderer = new BarRenderer3D(); // 渲染柱形图的样式
  renderer.setBaseOutlinePaint(Color.BLACK);
  renderer.setWallPaint(Color.gray); // 设置 3D效果围墙的颜色
  // 设置柱的颜色
  renderer.setSeriesPaint(0, Color.red);// 第一个柱形
  renderer.setSeriesPaint(1, Color.blue);// 第二个柱形
        // 设置柱的轮廓 颜色
     renderer.setSeriesOutlinePaint(0, Color.blue);
  renderer.setSeriesOutlinePaint(1, Color.red);
  renderer.setItemMargin(0.30d); // 设置平行柱的之间距离
  renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); // 显示每个柱的数值,并修改该数值的字体属性
  renderer.setBaseItemLabelsVisible(true);
     plot.setRenderer(renderer); // 使图表使用渲染效果
        // 设置柱的透明度
  plot.setForegroundAlpha(0.6f);
 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值