SChart LifeCycle - alterTickMark beforeAddingToAxis


#1

Team, 

We have a line chart with daily data year to date, in using an SCategoryAxis to represent these daily points, we use alterTIckMark to remove all but 15 tickMarks so the screen isn’t cluttered with the tickMarks.

The problem we are facing is that on the first load of the chart, it seems that alterTickMarks isn’t being called. As soon as a user touches the screen in any way, it looks great but until then, it’s very difficult to see anything and looks terrible. As a work around, we previously implemented a redrawChart call within sChartRenderFinished to work around this issue but that no longer seems to work.

Any thoughts?


#2
#pragma mark - ShinobiChart Delegate
- (void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis
{
    //remove some tick marks based on the number of data points and zoom, so that the xAxis isn't too crowded
    if([axis isXAxis]){
        
        float span = [[[axis axisRange] span] floatValue]; //basically the number of data points visible
        int m; //the mod number we'll use to thin out the label frequency
        
        m = (int)roundf(span/15.0); // show 15 data points on the chart regardless of zoom level
        if(m == 0) m = 1; //if there's less than 15 data points to show, show them all
        
        float tickValue = tickMark.value;
        BOOL remove = ((int)tickValue%m) != 0 && tickValue != 0;
        if(remove){
            tickMark.tickLabel.hidden = YES;
            tickMark.tickEnabled = NO;
        }
        else{
            tickMark.tickLabel.hidden = NO;
            tickMark.tickEnabled = YES;
        }
    }
    
}

- (void)sChartRenderFinished:(ShinobiChart *)chart
{
    if(self.shouldRedrawAfterRender){
        self.shouldRedrawAfterRender = NO;
        [chart redrawChart];
   }
}

Relevant code. when the chart is created and populated with the data source, should redrawafterrender is set to yes.

#3

Hi Stubiell,

Thanks for getting in touch!

Could you send us a sample project that shows your issue to info@shinobicontrols.com, along with an explanation of what your chart current does and what you want your chart to do?

This would really help us identify the source of your issue.

Kind Regards,
Andrew Polkinghorn


#4

I seem to have a similar problem - alterTickMark: is not called for some reason. I've set <SChartDatasource,SChartDelegate> in the class extension...all SChartDatasource delegates are called but not alterTickMark:...

Fixed! I'd forgotten to set _chart.delegate = self;