问题描述
代码如下:importjava.awt.Color;importjava.io.FileOutputStream;importjava.io.IOException;importorg.jfree.chart.ChartUtilities;importorg.jfree.chart.JFreeChart;importorg.jfree.chart.axis.NumberAxis;importorg.jfree.chart.labels.ItemLabelAnchor;importorg.jfree.chart.labels.ItemLabelPosition;importorg.jfree.chart.labels.StandardXYItemLabelGenerator;importorg.jfree.chart.plot.XYPlot;importorg.jfree.chart.renderer.xy.StackedXYBarRenderer;importorg.jfree.data.category.CategoryDataset;importorg.jfree.data.category.DefaultCategoryDataset;importorg.jfree.data.xy.CategoryTableXYDataset;importorg.jfree.data.xy.XYDataset;importorg.jfree.ui.TextAnchor;publicclasstest{publicstaticvoidmain(String[]args)throwsIOException{XYDatasetdata=getDataSet();NumberAxisnumberaxisY=newNumberAxis("生産量");numberaxisY.setStandardTickUnits(NumberAxis.createIntegerTickUnits());numberaxisY.setUpperMargin(0.10000000000000001D);numberaxisY.setRange(0,1200);NumberAxisnumberaxisX=newNumberAxis("生産量1");numberaxisX.setStandardTickUnits(NumberAxis.createIntegerTickUnits());numberaxisX.setUpperMargin(0.10000000000000001D);numberaxisX.setRange(0,6);StackedXYBarRendererstackedxybarrenderer=newStackedXYBarRenderer(0.14999999999999999D);stackedxybarrenderer.setDrawBarOutline(true);stackedxybarrenderer.setBaseItemLabelsVisible(false);stackedxybarrenderer.setBaseItemLabelGenerator(newStandardXYItemLabelGenerator());//stackedxybarrenderer.setItemLabelFont(newFont("黑体",Font.PLAIN,12));//stackedxybarrenderer.setItemLabelsVisible(true);stackedxybarrenderer.setBasePositiveItemLabelPosition(newItemLabelPosition(ItemLabelAnchor.OUTSIDE12,TextAnchor.BOTTOM_CENTER));//stackedxybarrenderer.setBaseToolTipGenerator(newStandardXYToolTipGenerator("{0}:{1}={2}",newSimpleDateFormat("yyyy"),newDecimalFormat("0")));stackedxybarrenderer.setMargin(0.2);stackedxybarrenderer.setSeriesPaint(0,newColor(0,11,220));stackedxybarrenderer.setSeriesPaint(1,newColor(51,129,50));stackedxybarrenderer.setSeriesPaint(2,newColor(255,0,0));XYPlotplot=newXYPlot(data,numberaxisX,numberaxisY,stackedxybarrenderer);;plot.setRangeGridlinesVisible(true);plot.setDomainGridlinesVisible(false);JFreeChartchart=newJFreeChart("工作",plot);FileOutputStreamfos_jpg=null;try{fos_jpg=newFileOutputStream("D:\client.jpg");ChartUtilities.writeChartAsJPEG(fos_jpg,0.5f,chart,800,500,null);}finally{try{fos_jpg.close();}catch(Exceptione){}}}privatestaticXYDatasetgetDataSet(){CategoryTableXYDatasetdataset=newCategoryTableXYDataset();dataset.add(100,100,"111111111111");dataset.add(100,200,"2222222222222");returndataset;}
解决方案
解决方案二:
专灭零回复贴
解决方案三:
web.xml配置了吗?
解决方案四:
numberaxisX.setRange(0,6);//去掉这句话就行了
这句话你知道是什么意思吗?去看看文档吧!
解决方案五:
dataset.add(50,100,"111111111111");//改成50,效果更明显,你的2个X都重叠了,看不到效果dataset.add(100,200,"2222222222222");
解决方案六:
来学习的
解决方案七:
在保证程序正确的基础上,请注意:我以前也碰到过类似的问题,好像需要单独安装JRE。当时就这么解决了,但感觉有点怪:),你不妨试试看。