Stacked bar chart in Objective C


Is it possible to create stacked bar chart in Objective C, as below ?


Hello Vimi,

Yes this is possible. I’d recommend you take a look at the Column Series sample that is available with our free trial.

To make the series stacked go to the SChart method that configures the series and you will have to set the stackIndex property to the same value for all of the series you want to stack.

-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index {
    SChartColumnSeries *columnSeries = [[SChartColumnSeries alloc] init];
    columnSeries.title = index == 0 ? @"2011" : @"2012";
    columnSeries.stackIndex = 0 // add this line
    return columnSeries;

There must also be a value for each element. For example if you wanted to achieve this in the Column Series sample you will have to provide Okra with a paired value (that is not present by default in the sample).

_sales[0] = @{@"Broccoli" : @5.65, @"Carrots" : @12.6, @"Mushrooms" : @8.4, @"Okra" : 0.7};
    _sales[1] = @{@"Broccoli" : @4.35, @"Carrots" : @13.2, @"Mushrooms" : @4.6, @"Okra" : @0.6};

I hope this answers your question for you.

Matt Webber