Note that there are some explanatory texts on larger screens.

plurals
  1. POAChartEngine renders null values
    primarykey
    data
    text
    <p>I have a BarChart which has some values which are set to MathHelper.NULL_VALUE so they are not rendered (it is supposed to leave blank positions in the chart). However, the null values are still rendered and look more like 0.0 as shown below.</p> <p><img src="https://i.stack.imgur.com/Oxxu2.png" alt="null values"></p> <p>If I log the values printed I can see that the NULL_VALUEs are present in the series:</p> <pre><code>10-23 09:50:24.206: DEBUG/ConsumptionChartBuilder(27359): x:16.0Y:1.0 10-23 09:50:24.206: DEBUG/ConsumptionChartBuilder(27359): x:17.0Y:3.0 10-23 09:50:24.206: DEBUG/ConsumptionChartBuilder(27359): x:18.0Y:1.7976931348623157E308 10-23 09:50:24.206: DEBUG/ConsumptionChartBuilder(27359): x:19.0Y:1.7976931348623157E308 10-23 09:50:24.216: DEBUG/ConsumptionChartBuilder(27359): x:20.0Y:6.0 10-23 09:50:24.216: DEBUG/ConsumptionChartBuilder(27359): x:21.0Y:1.7976931348623157E308 </code></pre> <p>Setting/Unsetting the min Y value doesn't change anything.</p> <p>I really need to differentiate between 0 and null and leaving points out of the bar chart results in some further odd rendering (the blank spaces are not the correct width)...</p> <p><strong>Does anyone know how to not render null values in an AChartEngine BarChart?</strong> </p> <p>Edit: Some code which reproduces it.</p> <pre><code> XYMultipleSeriesDataset multipleSeriesDataset = new XYMultipleSeriesDataset(); XYMultipleSeriesRenderer multipleSeriesRenderer = new XYMultipleSeriesRenderer(); XYSeriesRenderer renderer= new XYSeriesRenderer(); //set up renderer(s) renderer.setColor(Color.RED); multipleSeriesRenderer = new XYMultipleSeriesRenderer(); multipleSeriesRenderer.setInScroll(true); multipleSeriesRenderer.setPanEnabled(false, false); multipleSeriesRenderer.setZoomEnabled(false, false); multipleSeriesRenderer.setAntialiasing(true); multipleSeriesRenderer.setShowLabels(true); multipleSeriesRenderer.setShowLegend(false); multipleSeriesRenderer.setYLabelsAlign(Paint.Align.LEFT); multipleSeriesRenderer.setApplyBackgroundColor(true); multipleSeriesRenderer.setMargins(new int[]{20, 3, 0, 0}); multipleSeriesRenderer.setMarginsColor(Color.WHITE); multipleSeriesRenderer.addSeriesRenderer(renderer); multipleSeriesRenderer.setXLabelsAlign(Paint.Align.CENTER); //text size final float scale = getResources().getDisplayMetrics().density; multipleSeriesRenderer.setLabelsTextSize((int)(scale*10+0.5f)); multipleSeriesRenderer.setXLabelsColor(Color.BLACK); multipleSeriesRenderer.setYLabelsColor(0,Color.BLACK); multipleSeriesRenderer.setShowAxes(false); multipleSeriesRenderer.setBackgroundColor(Color.TRANSPARENT); //set max and min of axis multipleSeriesRenderer.setYAxisMin(0); multipleSeriesRenderer.setYAxisMax(10); multipleSeriesRenderer.setXAxisMax(7.5); multipleSeriesRenderer.setXAxisMin(0.5); multipleSeriesRenderer.setBarSpacing(0.1); //set up series XYSeries series = new XYSeries("test"); series.add(1, MathHelper.NULL_VALUE); series.add(2, 1); series.add(3, 6); series.add(4, MathHelper.NULL_VALUE); series.add(5, 0); series.add(6, 5); series.add(7, MathHelper.NULL_VALUE); multipleSeriesDataset.addSeries(series); //add x labels to replicate my original code multipleSeriesRenderer.setXLabels(0); multipleSeriesRenderer.addXTextLabel(1, "Mon"); multipleSeriesRenderer.addXTextLabel(2, "Tue"); multipleSeriesRenderer.addXTextLabel(3, "Wed"); multipleSeriesRenderer.addXTextLabel(4, "Thu"); multipleSeriesRenderer.addXTextLabel(5, "Fri"); multipleSeriesRenderer.addXTextLabel(6, "Sat"); multipleSeriesRenderer.addXTextLabel(7, "Sun"); ((LinearLayout)findViewById(R.id.layout_graph)).addView(ChartFactory.getBarChartView(this, multipleSeriesDataset, multipleSeriesRenderer, BarChart.Type.DEFAULT)); </code></pre> <p><strong>Edit number 2: Screenshots of the above code:</strong></p> <p>With null values:</p> <p><img src="https://i.stack.imgur.com/Sqt2g.png" alt="screenshot with null values"></p> <p>If I don't add the null values then the graph looks skewed as shown here where the bars touch one another. </p> <p><img src="https://i.stack.imgur.com/cSYd4.png" alt="screenshot without null values"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload