bar with value zero

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
EdwardKing
Posts: 6
Joined: Fri May 06, 2011 2:05 am
antibot: No, of course not.

bar with value zero

Post by EdwardKing » Mon Jan 05, 2015 7:22 am

I want to draw a bar,it is four items in this bar,such as Item1,Item2,Item3 and Item4,but Item2's value is zero. When I run it,I find bar only contains Item1,Item3 and Item4,I want to contains Item2,but I don't know how to show bar with value is zero, How to do it? Thanks

Code: Select all

DefaultCategoryDataset dataset=new DefaultCategoryDataset();
   dataset.setValue(16243,"Item1","");
   dataset.setValue(0,"Item2","");
   dataset.setValue(3,"Item3","");
   dataset.setValue(1,"Item4","");
   JFreeChart chart=ChartFactory.createBarChart("Category",null,"Value", dataset);   
   CategoryPlot plot=(CategoryPlot)chart.getPlot();
   NumberAxis localNumberAxis = (NumberAxis)plot.getRangeAxis();
                localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
                localNumberAxis.setUpperMargin(0.15D);
                CategoryItemRenderer localCategoryItemRenderer = plot.getRenderer();
                localCategoryItemRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
                localCategoryItemRenderer.setSeriesItemLabelsVisible(0, Boolean.TRUE);
   localCategoryItemRenderer.setSeriesItemLabelsVisible(1, Boolean.TRUE);
   localCategoryItemRenderer.setSeriesItemLabelsVisible(2, Boolean.TRUE);
   localCategoryItemRenderer.setSeriesItemLabelsVisible(3, Boolean.TRUE);
   plot.setForegroundAlpha(0.8f);   
   ChartUtilities.writeChartAsJPEG(response.getOutputStream(),chart, 640 , 400 );

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: bar with value zero

Post by paradoxoff » Mon Jan 05, 2015 11:34 am

Based on the values that you have shown, I would assume that only the bar for Item1 with a value of 16243 is actually visible.
In any case: technically, it is not possible to "show" anything that has zero size. Maybe you could try to label the bars, so that the user can see the value?

Locked