关于jfreechart做柱状图的问题?
为什么我用jfreechart做柱状图,最多只能显示5个数据?
请高手们帮忙!
代码如下:
package jfreecharttest;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import org.jfree.data.category.*;
import org.jfree.chart.*;
import org.jfree.data.*;
import org.jfree.chart.plot.*;
public class CategoryServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK ";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType( "image/jpeg ");
response.reset();
CategoryDataset data=getDataSet();
JFreeChart chart=ChartFactory.createBarChart( "aaa ", "bbb ", "ccc ",data,PlotOrientation.VERTICAL,true,false,false);
ChartUtilities.writeChartAsJPEG(response.getOutputStream(),1,chart,1024,600,null);
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
private static CategoryDataset getDataSet2() {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(100, "北京 ", "苹果 ");
dataset.addValue(300, "上海 ", "苹果 ");
dataset.addValue(150, "广州 ", "苹果 ");
dataset.addValue(200, "北京 ", "梨子 ");
dataset.addValue(200, "上海 ", "梨子 ");
dataset.addValue(200, "广州 ", "梨子 ");
dataset.addValue(300, "北京 ", "葡萄 ");
dataset.addValue(300, "上海 ", "葡萄 ");
dataset.addValue(300, "广州 ", "葡萄 ");
dataset.addValue(400, "北京 ", "香蕉 ");
dataset.addValue(400, "上海 ", "香蕉 ");
dataset.addValue(400, "广州 ", "香蕉 ");
dataset.addValue(500, "北京 ", "荔枝 ");
dataset.addValue(500, "上海 ", "荔枝 ");
dataset.addValue(500, "广州 ", "荔枝 ");
dataset.addValue(100, "北京 ", "苹果 ");
dataset.addValue(300, "上海 ", "苹果 ");
dataset.addValue(150, "广州 ", "苹果 ");
return dataset;
}
//Clean up resources
public void destroy() {
}
}
[解决办法]
你的第六条数据是重复数据,
dataset.addValue(100, "北京 ", "苹果 ");
dataset.addValue(300, "上海 ", "苹果 ");
dataset.addValue(150, "广州 ", "苹果 ");
改成:
dataset.addValue(700, "北京 ", "小苹果 ");
dataset.addValue(700, "上海 ", "小苹果 ");
dataset.addValue(700, "广州 ", "小苹果 ");
[解决办法]
这种问题基本就是 bruni(不如你) 说的那样,是由于有完全重复的数据。
dataset.addValue(500, "北京 ", "荔枝 ");
dataset.addValue(500, "上海 ", "荔枝 ");
dataset.addValue(500, "广州 ", "荔枝 ");
后面这部分用
dataset.addValue(600, "北京 ", "苹果 ");
dataset.addValue(600, "上海 ", "苹果 ");
dataset.addValue(600, "广州 ", "苹果 ");
不可能还是5组