Need ability to reference chart.theme from chart's data source delegate


#1

I’m working on an alternate way to store series line colors in my custom theme (I’m having trouble accomplishing this subclassing SChartTheme–that’s in another topic’s thread).

Anyway, as part of doing this, I added an array of desired line colors to my custom theme (CustomChartTheme), and coded a reference to it from the data source’s delegate seriesAtIndex method, like below.  This works, and hey, is kind of an OK way to workaround this–at least it keeps the configuration of line colors encapsulated in the theme rather than scattered out to the data source(s).

The potential problem is the ShinobiChart.theme property is marked deprecated and replced by the applyTheme method.  OK, this makes sense when the .theme property is used in a “write” mode. But if this property isn’t replaced by a method to retrieve the theme for reference, then this potentially useful scenario of looking up theme information as below will no longer be possible.

Is it possible to add a getTheme type method before the .theme property is removed so this scenario can continue to be possible?  Or is it already there and I didn’t notice it?

-(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index
{
    SChartLineSeries *lineSeries = [[SChartLineSeries alloc] init];
    lineSeries.title = [NSString stringWithFormat:@"Series %ld", (long)index];

    CustomChartTheme *theme = (CustomChartTheme *) chart.theme;
    lineSeries.style.lineColor = [[theme.lineStyles objectAtIndex:index] lineColor];
    
    return lineSeries;
}

#2

Hi Rob,

Thanks for getting in touch!

This isn’t something that we support out of the box in our latest version.

However, a work around solution would be to create a subclass of ShinobiChart and give it a public CustomChartTheme property.

Then override the “applyTheme:” method in your subclass to store the theme passed in using your newly created CustomChartTheme property and then call super on that method.

Now you can access the theme you passed using the getter of the CustomChartTheme property.

Let me know if you have any issues.

Kind Regards,
Andrew Polkinghorn