jfreechart 时序图柱状图(混合图形制图)急!急!大急!急!急! ?????????
急!急!大急!急!急!侠急!用过jfreechart 没,jfreechart 制作线形的时序图很好做,如果要再上面添加柱形图怎么添加。本人将柱形图已经添加到时序图中了,为什么我的柱形图总是会往后移动半个刻度啊,也就是柱形图对应的X轴上的刻度会放在两个刻度的中间位置呢??高手们 求解啊!求解啊
[解决办法]
能把图发一下吗? 应该是图设置的问题
[解决办法]
这个也不难
时序图做好之后,在输入图片之前,再追加柱形图
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 , "" , month); } /* dataset.addValue(38000 , "" , "J2EE web应用开发"); dataset.addValue(31000 , "" , "基于J2EE的Ajax开发"); dataset.addValue(29000 , "" , "JavaScript权威指南"); dataset.addValue(25000 , "" , "J2SE应用开发"); */ return dataset; } public ArticleService getAs() { return as; } public void setAs(ArticleService as) { this.as = as; }}