Android - Set Other Color For Each Data Point In Barseries (shinobicharts)
I trying use shinobicharts to design like as this chart: http://www.upsieutoc.com/images/2014/04/19/barseries.png BarSeries I used BarSeries, and i having a few problem following:
Solution 1:
Apparently you can't.
The solution is to have 3 series with one value each, rather than one series with 3 values. E.g.:
ChartFragmentchartFragment= (ChartFragment) getFragmentManager().findFragmentById(R.id.chart);
ShinobiChartshinobiChart= chartFragment.getShinobiChart();
NumberAxisxAxis=newNumberAxis();
xAxis.setPosition(Position.REVERSE);
shinobiChart.addXAxis(xAxis);
CategoryAxisyAxis=newCategoryAxis();
shinobiChart.addYAxis(yAxis);
BarSeriesseries1=newBarSeries();
series1.setTitle("Country");
BarSeriesStylebss1= series1.getStyle();
bss1.setAreaColor(Color.RED);
DataAdapter<Integer, String> adapter = newSimpleDataAdapter<Integer, String>();
adapter.add(newDataPoint<Integer, String>(20, "Spain"));
series1.setDataAdapter(adapter);
shinobiChart.addSeries(series1);
BarSeriesseries2=newBarSeries();
series2.setTitle("Country");
BarSeriesStylebss2= series2.getStyle();
bss2.setAreaColor(Color.GREEN);
DataAdapter<Integer, String> adapter = newSimpleDataAdapter<Integer, String>();
adapter.add(newDataPoint<Integer, String>(25, "Malaysia"));
series2.setDataAdapter(adapter);
shinobiChart.addSeries(series2);
BarSeriesseries3=newBarSeries();
series3.setTitle("Country");
BarSeriesStylebs3= series3.getStyle();
bss3.setAreaColor(Color.BLUE);
DataAdapter<Integer, String> adapter = newSimpleDataAdapter<Integer, String>();
adapter.add(newDataPoint<Integer, String>(30, "France"));
series3.setDataAdapter(adapter);
shinobiChart.addSeries(series3);
Solution 2:
I may be able to offer a partial answer for point 2 of your question: "i want set other color for each data point like in the image above. (red, green, purple)"
Have you tried subclassing SChartBarSeries? If not, try this:
#pragma mark - Custom Styling of Bars@interfacecustomBarSeries:SChartBarSeries@end@implementationcustomBarSeries
- (SChartBarSeriesStyle *)styleForPoint:(id<SChartData>)point {
SChartBarSeriesStyle *newStyle = [super styleForPoint:point];
int country = [[point sChartXValue] intValue];
// datapoint specific customization:switch (country) {
case COUNTRY_FRANCE:
newStyle.areaColor = [UIColor redColor];
break;
case COUNTRY_MALAYSIA:
newStyle.areaColor = [UIColor greenColor];
break;
case COUNTRY_SPAIN:
newStyle.areaColor = [UIColor purpleColor];
break;
}
return newStyle;
}
@end// And in you chart's "sChart: seriesAtIndex:" method, use your custom bars instead of the shinobi default:
-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index {
switch (index) {
case COUNTRY_BARS_SERIE_INDEX:
{
// Instead of this: SChartBarSeries *barSeries = [SChartBarSeries new];
customBarSeries *barSeries = [customBarSeries new]; // <-- Here you use your customized sub-class
barSeries.title = @"Countries";
// Style things that are common to all data points in the serie
barSeries.style.dataPointLabelStyle.displayValues = SChartDataPointLabelDisplayValuesX;
barSeries.style.dataPointLabelStyle.showLabels = YES; // <-- You may need this as wellreturn barSeries;
break;
}
}
}
No idea if the label parts of this works or where would the labels be place. I just stumbled upon the label property of the dataPointStyle when writing this example so you'll have to play with it see what happens.
As for the names of the countries on the Y axis, you have to customise the Y axis for that, it doesn't come with the series.
Hope that helps!
Post a Comment for "Android - Set Other Color For Each Data Point In Barseries (shinobicharts)"