Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bar color is visible for 0 values in AchartEngine, android

I have used AchartEngine to display Barchart. In my chart bar color is visible for 0 values also. I have checked like the following.. but it set all the values to transparent. I want to set the bar color to values having greater than 0.

CategorySeries series = new CategorySeries("");
        for (int i = 0; i < y_onemonth.length; i++) {
            series.add("Bar" + (i + 1), y_onemonth[i]);
        }

        XYMultipleSeriesDataset dataSet = new XYMultipleSeriesDataset();
        dataSet.addSeries(series.toXYSeries()); // number of series

        // customization of the chart

        XYSeriesRenderer renderer = new XYSeriesRenderer();
        for (int i = 0; i < y_onemonth.length; i++) {
        if(y_onemonth[i]==0)
        {
            renderer.setColor(Color.TRANSPARENT);
        }
        else
        {
            renderer.setColor(Color.RED);
        }
        }

Update: I changed my code as you mention, but get the chart like this. I have value for 19th of the month, But it doesn't visible.

enter image description here

like image 745
Manikandan Avatar asked Nov 19 '13 14:11

Manikandan


1 Answers

I have had some success replacing 0 values with MathHelper.NULL_VALUE. You can find the documentation for that class here.

EDIT : when filling your data Series, you could try something like this instead :

for (int i = 0; i < y_onemonth.length; i++) {
    double doubleValue = MathHelper.NULL_VALUE;
    if (y_onemonth[i] != 0){
        doubleValue = y_onemonth[i];
    }
    series.add("Bar" + (i + 1), doubleValue);
}

Hope this will help ;-)

like image 103
2Dee Avatar answered Oct 21 '22 09:10

2Dee