Set axis tick label colour to the line colour of the first associated series


I have a chart with several (maybe one, more likely five) Y axes, each with only one associated series. In the interest of saving space, I’d like to hide axes labels and colour axes tick labels per the line colour of the associated series. I can colour tick labels just fine (per tickMark.tickLabel.textColor in the sChart:alterTickMark:beforeAddingToAxis: delegate method) and retrieve the line colour for an arbitrary series (by way of [((SChartLineSeriesStyle *) [(SChartLineSeries *) [[chart allChartSeries] objectAtIndex:0] style]) lineColor]), but I’m sort of stuck when it comes to determining the first (only) series attached to that axis. Ought I keep track of which axis gets assigned to the series by sChart:yAxisForSeriesAtIndex: in the datasource, or am I going about this completely backwards?


I was crazy over-thinking this. Here’s the solution I came up with in case anyone else is trying to do this:

- (void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis
    if (axis.axisOrientation == SChartOrientationVertical)
        NSUInteger axisIndex = [[chart allYAxes] indexOfObject:axis];
        SChartLineSeries *series = (SChartLineSeries *) [chart allChartSeries][axisIndex];
        tickMark.tickLabel.textColor = [[(SChartLineSeries *) series style] lineColor];

This is fairly unsafe code; if you’re not absolutely certain that there will be at least as many series as axes, you should add some range checking to make sure the series actually exists before trying to retrieve it from [chart allChartSeries].