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.
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 ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With