Get dataPoint location in view


Hi everyone,

in this method : - (void)sChart:(ShinobiChart *)chart toggledSelectionForPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series atPixelCoordinate:(CGPoint)pixelPoint;

I would like to know what is the location in view of the selected dataPoint.

Not the the dataPoint xValue and yValue the location it will have on the view where my chart is inserted.

Best regards :wink:


There is an undocumented method on the SChartAxis object  -mapPixelValueForDataValue:** usingSeries:** that will map a data value to a pixel value within the coordinate system of your plot area (chart.canvas.glView). You will need to call this method on both your X & Y axes to get the full pixel coordinate for your data value.

We are actually planning on adding a set of methods to our API next release (soon!) that will be adding a user friendly way of mapping between data & chart pixel coordinates. So I must stress to you that the method I mentioned above is liable to change, and probably sooner rather than later! For posterity, at the time of writing this, the most recent charts release is 2.2.1.



Just what i needed thank you very much :smiley:


Oh and just to add, the series parameter is used to take into account any offset that might be applied to the series (For exmaple, when bar series are offset next to eachother on the same datapoint.)


Hello any ideia what can i use has replacement in the version 2.3 ? 


I was trying to use the:


double xPoint = [chart.xAxis pixelValueForDataValue:dataPoint.xValue];
    double yPoint = [chart.yAxis pixelValueForDataValue:dataPoint.yValue];

but not getting the same results as before.


Actually the y location is fine i just need to work on the x location.


Can I ask what is different about the result?


With version 2.2.1

double xPoint = [chart.xAxis mapPixelValueForDataValue:[dataPoint.xValue doubleValue] usingSeries:series];
    double yPoint = [chart.yAxis mapPixelValueForDataValue:[dataPoint.yValue doubleValue] usingSeries:series];

2013-08-14 14:00:17.845 managed-services[15568:907] xPoint = 192.062500
2013-08-14 14:00:17.847 managed-services[15568:907] yPoint = 243.922917

With version 2.3:

double xPoint = [chart.xAxis pixelValueForDataValue:dataPoint.xValue];
    double yPoint = [chart.yAxis pixelValueForDataValue:dataPoint.yValue];

2013-08-14 13:57:41.346 managed-services[15540:907] xPoint = 32.187500
2013-08-14 13:57:41.348 managed-services[15540:907] yPoint = 231.407501



If I am right, you guys released a new version yesterday. Can you let us know what are the new methods that would make our life easier mapping form dataPoints to pixels and viceversa? Any way to know to which series a datapoint that has been tapped belongs?

Many thanks.



There are a number of methods on SChartAxis that allow this type of mapping. Check out the methods under the  Data - Pixel Conversions heading in our SChartAxis documentation.


The 2.3 method pixelValueForDataValue: should definitely return the pixel value with respect to the plot area. Was the undocumented 2.2.1 method mapPixelValueForDataValue: returning the coordinates with respect to the plot area (chart.canvas.glView)?

I could have been mistaken about the undocumented 2.2.1 method in my original response.



I belive 2.2.1 method was giving me pixel value with respect to the glView.


I just tested this. The undocumented 2.2.1 method was giving it’s coordinates with respect to the chart’s canvas (chart.canvas), which also includes the axis & title area. The new 2.3 method gives its coordinates with respect to the plot area (chart.canvas.glView).

This explains why the coordinates were slighly off in the X direction - the X axis was being taken into account in 2.2.1. Now you know this, it shouldn’t be hard to update your app to fix this change. 

Hope this helps.



I am not getting the right value for the X axis when using ‘dataValueForPixelValue’. I detect the location in the view using touchesBegan and then [touch locationInview] and pass those values for both x and y to the X and Y axes.

PicPaste: Chart_Screenshot-N4gOxVoU.png

For that case I get these values: Touch.x=345.000000, y=282.000000. DataValue = 12460.098434, 20.514257

and the dataValue for x I was expecting was something about 12500.

For Y it seems to work OK but not for X. I have 212 StepLineSeries to simulate the effect I described in: but neither the delegate methods toggledSelectionForPoint nor toggledSelectionForSeries is returning me the right point/series when I am tapping.

I have tried substracting the value returned chart.getPlotAreaFrame.origin.x but that didn’t help. I’m using 2.3.

Any ideas what is wrong?


@Jan, I just saw your response right after I posted. Getting the touch location based on:

[self.chart.canvas glView]

seems to work fine. Thanks.


I’ve noticed that the pixelValueForDataValue: doesn’t seem to work when the xAxis is a SChartDateTimeAxis. When using the date axis if I pulled out a value using dataValueForPixelValue then put it back in to pixelValueForDataValue the value would be incorrect by several orders of magnitude. Simply switching to a SChartNumberAxis is giving me correct values (though of course my axis is now labelled incorrectly)


My X axis is of the type SChartCategoryAxis.

The new 2.3 method is allways giving me the same value even if a choose columns with diferent x values.

chart screenshoot

- (void)doActionForSelectedDataPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series onChart:(ShinobiChart*)chart{
    double xPoint = [chart.xAxis pixelValueForDataValue:dataPoint.xValue];
    double yPoint = [chart.yAxis pixelValueForDataValue:dataPoint.yValue];
    NSLog(@"xValue - %@", dataPoint.xValue);
    NSLog(@"xPoint = %f",xPoint);
    NSLog(@"yPoint = %f",yPoint);

2013-08-16 10:38:44.011 managed-services[1157:c07] xValue - P4
2013-08-16 10:38:44.011 managed-services[1157:c07] xPoint = 32.187500
2013-08-16 10:38:44.012 managed-services[1157:c07] yPoint = 303.434998

2013-08-16 10:38:22.747 managed-services[1157:c07] xValue - P3
2013-08-16 10:38:22.748 managed-services[1157:c07] xPoint = 32.187500
2013-08-16 10:38:22.748 managed-services[1157:c07] yPoint = 231.407501

2013-08-16 10:37:46.587 managed-services[1157:c07] xValue - P2
2013-08-16 10:37:46.588 managed-services[1157:c07] xPoint = 32.187500
2013-08-16 10:37:46.588 managed-services[1157:c07] yPoint = 0.000000

2013-08-16 10:37:03.396 managed-services[1157:c07] xValue - P1
2013-08-16 10:37:03.397 managed-services[1157:c07] xPoint = 32.187500
2013-08-16 10:37:03.398 managed-services[1157:c07] yPoint = 266.654999


If i use SChartNumberAxis for the X axis the x values returned by the 2.3 method seem correct :slight_smile:

Maby theres a problem if the function when the axis are not SChartNumberAxis? 


I made some experiments with the SChartCategoryAxis … in the :

- (id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(int)dataIndex forSeriesAtIndex:(int)seriesIndex

If i set the dataPoint.xValue to a string for all the columns the 2.3 method returns a bad value 

but if i set numbers for the dataPoint.xValue it returns a good value.

Not sure if the 2.3 method doesnt respond well if the xValue of the dapaPoint is a String.


the 2.3 -(float)pixelValueForDataValue:(id)data;

is also not returning correct values for donut charts.