日期:2014-05-18 浏览次数:20832 次
plot.setDataset(1, lineDataset); DefaultCategoryDataset barDataset = new DefaultCategoryDataset(); barDataset.addValue(1.0, barSeries1, category1); barDataset.addValue(4.0, barSeries1, category2); barDataset.addValue(3.0, barSeries1, category3); barDataset.addValue(5.0, barSeries1, category4); CategoryPlot plot = chart.getCategoryPlot(); plot.setDataset(2, barDataset); plot.mapDatasetToRangeAxis(1, 1); plot.setRangeAxis(2, domainAxis);
------解决方案--------------------
package com.article.action; import java.awt.Font; import java.util.List; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.CategoryLabelPositions; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.title.TextTitle; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.DefaultCategoryDataset; import com.article.service.ArticleService; import com.opensymphony.xwork2.ActionSupport; public class BarChart3DAction extends ActionSupport{ private ArticleService as; private JFreeChart chart; public JFreeChart getChart(){ chart = ChartFactory.createBarChart3D( "文章发布数量统计图", // 图表标题 "月份", // 目录轴的显示标签 "数量", // 数值轴的显示标签 getDataSet(), // 数据集 //PlotOrientation.HORIZONTAL , // 图表方向:水平 PlotOrientation.VERTICAL , // 图表方向:垂直 false, // 是否显示图例(对于简单的柱状图必须是false) false, // 是否生成工具 false // 是否生成URL链接 ); //重新设置图标标题,改变字体 chart.setTitle(new TextTitle("文章发布数量统计图", new Font("黑体", Font.ITALIC , 22))); CategoryPlot plot = (CategoryPlot)chart.getPlot(); //取得横轴 CategoryAxis categoryAxis = plot.getDomainAxis(); //设置横轴显示标签的字体 categoryAxis.setLabelFont(new Font("宋体" , Font.BOLD , 22)); //分类标签以45度角倾斜 categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); categoryAxis.setTickLabelFont(new Font("宋体" , Font.BOLD , 18)); //取得纵轴 NumberAxis numberAxis = (NumberAxis)plot.getRangeAxis(); //设置纵轴显示标签的字体 numberAxis.setLabelFont(new Font("宋体" , Font.BOLD , 22)); return chart; } //返回一个CategoryDataset实例 private CategoryDataset getDataSet() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); List list= as.BarChart3D(); for (int i = 0; i < list.size(); i++) { Object[] row = (Object[]) list.get(i); Integer month = (Integer) row[0]; Integer shuliang = (Integer) row[1]; dataset.addValue(shuliang , ""