Is there a working example that uses subclasses SChartTheme?


I’d like to develop my own Chart Theme to use in an app, which would be a great way to make sure all charts in the app follow a consistent theme.  I know overriding SChartTheme is supported and is *somewhat* documented.  However I just can’t get it to work for me when it comes to setting up styles for the series lines in a line chart.  

I started by using the demo iPad app to get a theme pretty close to what I wanted, then e-mailed it to me.  I received four files, which seemed to be sort of generating the output in two different ways…one way using [theme setValue … forKey] (CustomChartTheme.h, CustomChartTheme.m); the second way Subclassing SChartTheme (ShinobiPlaySChartTheme.h and .m). 

After trying I find neither of these sets of files will compile in my iOS7 project.  They contain various deprecated methods and syntax.   But, I went ahead and imported ShinobiPlayShartTheme.* anyway and did my best to fix all the errors so I could get it to compile.  Once compiled, it just crashes my app, though.  It *seems* to me that these output files are referencing overrides that have been deprecated in the library?  

So with some re-rigging such as removing the setStyles and setColors methods, and only calling the initialiseThemeWithDefaults method from my init, I can get the theme to “do something”, such as setting the background color of the chart and some font sizes.  But I can’t get SChartLineSeriesStyle logic to take effect.  The documentation mentions in passing to override lineSeriesStyleForSeriesAtIndex.  If I do this, my app goes back to crashing again.  

What is missing from the picture is an example from your team where an SChartTheme override is done and works (with the latest version of the library and a recent version of iOS).  I feel like the architecture of what is designed is perfect, but I’m finding it impossible to implement successfully.

The only thing I’ve done that works is to force the line style in the DataSource, but this is not ideal since the SChartTheme has all the wiring to encapsulate defaults without having to do it “manually” with every chart creation.

Is there an example/blog post/tutorial I’m missing?  And BTW, even if there is, IMO the documentation on this feature needs a serious revisit to make it simpler to implement.




Hi Rob,

We are currently working on a big revamp to the documentation in this area (and others). The rush of updates since iOS7 came out, along with the huge theming overhaul at the same time meant that sample code, and ShinobiPlay were a little behind on the times.

With the sample theme from the Chart Designer, my recommendation would be to ignore it for now. As with the documentation, we plan to revisit this soon to bring it up to speed with the new way the SChartTheme works, but this is still in the pipeline.

As another note, make sure that when you are applying the theme to the chart, you use the new API;

[chart applyTheme:customTheme];

Now onto the theme itself. You should only need to override the *StyleForSeriesAtIndex:selected: methods, returning the SChartLineSeriesStyle, etc. for each.

I’d be interested in how you get on with this, so do keep us in the loop!


Hi tkelly,

OK, this actually I had already done, and it causes the program to crash. 

What I’ve done is simplified my theme as much as possible (including only the override you told me to), and then imported into your “Getting Started” sample app, and applied the theme.  It results in an EXC_BAD_ACCESS crash in the [SChartGLView convertUIColorToColour4f:] method. 

I’ve uploaded the project so you can try yourself…download link:

Maybe I’m just missing something basic, but this is kind of (no, really) frustrating from this end. Of course I know themes do work, since the ones baked into the library work…but getting from theory to practice is elusive at best. Would appreciate knowing what “does” work, not what “should” work :confused:.  

Here’s the theme .m file, and below that how I’m applying it to the chart in the “Getting Started” app:

#import "CustomChartTheme.h"
#import <ShinobiCharts/SChartBoxGestureStyle.h>

@implementation CustomChartTheme
    NSMutableArray *lineSeriesStyles;

- (id)init
    self = [super init];
    if (self) {
        [self initializeTheme];
    return self;

- (SChartLineSeriesStyle *)lineSeriesStyleForSeriesAtIndex:(NSInteger)seriesIndex selected:(BOOL)selected
    if (seriesIndex < [lineSeriesStyles count])
        return [lineSeriesStyles objectAtIndex:seriesIndex];
        return nil;

- (void)initializeTheme
    lineSeriesStyles = [NSMutableArray new];
    SChartLineSeriesStyle *ls = [SChartLineSeriesStyle new];
    ls.lineColor = [UIColor cyanColor];
    ls.showFill = YES;
    ls.areaColor = [UIColor blueColor];
    ls.fillWithGradient = YES;
    ls.pointStyle.showPoints = YES;
    ls.lineWidth = @2;
    [lineSeriesStyles addObject:ls];

    ls = [SChartLineSeriesStyle new];
    ls.lineColor = [UIColor purpleColor];
    ls.showFill = YES;
    ls.areaColor = [UIColor redColor];
    ls.fillWithGradient = YES;
    ls.pointStyle.showPoints = YES;
    ls.lineWidth = @2;
    [lineSeriesStyles addObject:ls];


(stuff up here as in the Shinobi Sample)    
    // Apply theme
    CustomChartTheme *theme = [CustomChartTheme new];
    [_chart applyTheme:theme];


Thanks for that sample, we’ll look into it and let you know soon!


Right, as an overdue update, I’ve been looking at how to get this working, but come to the conclusion that its not possible under the current code. We are in the process of a very large API review across the entire framework, which will include making the theming API easier to use and possible to subclass.

In the meanwhile, the best I can suggest is to use the closest theme to your desired outcome, and modify the style objects themselves.


I ran into the same problem today, writing May 21, 2014. Any updates on when this will be done? The allegedly elegant theming api is one of the reasons we want to go for shinobicharts as opposed to other alternatives, but at this point, not so elegant.