Why does setDataPoint:fromSeries:fromChart: pass in an instance of SChartDataPoint and not my custom object?


#1

In my chart datasource I return an instance of a custom NSObject subclass that complies with the SCDataPoint protocol.  This class has additional attributes that are useful for creating a custom tooltip.  However, when I subclass the SChartCrosshairTooltip and override the behavior of setDataPoint:fromSeries:fromChart:, the data point is an instance of an SChartDataPoint, not my custom object.  Why isn’t it giving me the object I supplied it???

static NSDateFormatter *dateFormatter = nil;

  • (void)setDataPoint:(id<SChartData>)dataPoint fromSeries:(SChartSeries *)series fromChart:(ShinobiChart *)chart {
        if (dateFormatter == nil) {
            dateFormatter = [[NSDateFormatter alloc] init];
            dateFormatter.dateStyle = NSDateFormatterLongStyle;
        }

    NSString *date = [dateFormatter stringFromDate:[(HEMChartDataPoint *)dataPoint date]];
    self.label.lineBreakMode = NSLineBreakByWordWrapping;
    self.label.numberOfLines = 2;
    self.label.text = [NSString stringWithFormat:@"%@\n%f %@", date, [dataPoint.sChartYValue floatValue], chart.yAxis.title];
}

Setting a breakpoint in this method and inspecting the class of the object passed in reveals that it is an instance of a SChartDataPoint.

To make matters worse, the API doesn’t give any reference index with which one could derive the source data from which the data point was created.  What am I missing???


#2

Hi Wayne,

I’m afraid we currently create some internal datapoints when they’re passed to the chart, and these are what are returned through the delegate methods. We provide an “sChartDataPointIndex” method (or just “index” on SChartDataPoint, which forwards to this). These should allow you to get your original datapoint from your datasource - let me know if you have any trouble with this!

Kind regards,

Rob


#3

This is a quite bizzare/broken design. At least then offer a easy way to get the original data point object from the internal representation. E.g. dataPoint.original.