2

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.

null values

If I log the values printed I can see that the NULL_VALUEs are present in the series:

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

Setting/Unsetting the min Y value doesn't change anything.

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)...

Does anyone know how to not render null values in an AChartEngine BarChart?

Edit: Some code which reproduces it.

    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));

Edit number 2: Screenshots of the above code:

With null values:

screenshot with null values

If I don't add the null values then the graph looks skewed as shown here where the bars touch one another.

screenshot without null values

4

2 に答える 2

0

値を追加しないことをお勧めしMathHelper.NULL_VALUEます。他のものを追加するだけです。

于 2012-10-23T11:44:26.343 に答える
0

私はあなたの意図がこれらのMathHelper.NULL_VALUEバーを空白にすることだと思うので、これらのバーの色を透明に設定できるので、あなたの意図が私が述べた場合には表示されません。したがって、これらのバーを表示したい場合は、値を{} 空欄。

于 2012-11-09T06:37:33.490 に答える