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);
}