Point in line graph selected and toggledSelectionForPoint called even when not tapping on point


#1

I’d like to respond to selection changes in my graph when tapping on a plot point. I set a delegate on my graph, set the selection mode of the line to SelectionPoint and implemented the toggledSelectionForPoint delegate.

Everything is working fine but the delegate and the selection are ALWAYS changed even if I tap somewhere outside of the line or between points. It simply selects the closed point and gives me the pixel coordinate of the tap. 

Is there a way to disable this functionality? I only want to select a point if I actually tap on it.

Additionally, how do I get the selected point later? When I close my “selection bubble”, I’d like to reset the selection programmatically.

Thanks in advance for your help.


#2

Any input on this?

I could not find any solution to either problem (selection in middle of line, deselecting point programmatically)


#3

Hi Kalle,

I can’t tell from your pictures whether you are using a subclass of the SChartCrosshairTooltip or whether you are placing a UIView in front of your chart.

If you are using a tooltip subclass then you should be able to make the tooltip snap to the nearest data point by setting the interpolatePoints property on your chart’s crosshair to NO. If you are not using a crosshair on your chart, is there a reason why you chose not to use one?

Jan


#4

I have a custom view because I didn’t know about the SChartCrosshairTooltip class.  But after I set interpolatePoints to NO, the delegate will always return proper points. That part is fixed now.

But how do I deselect the point programmatically?


#5

To delselect the point programatically, you will have to keep track of which points are being selected (as a SChartDatapoint ivar). Then when you want to programatically deselect the point, simply set the selected property to NO on the datapoint and call [chart redrawChart].

Let me know if this helps!


#6

Unfortunately, this doesn’t work. That is what I tried. I keep a ivar to the selected point, set the selected property to NO and redraw the chart. But the chart is not actually redrawn (or at least the selection stays active):

_selectedDataPoint.selected = NO;
[chart reloadData];
 
 (lldb) po _selectedDataPoint
$0 = 0x08465ec0 { index=5, x=1325173173.297102, y=122.7664, selected=Y }
 (lldb) po _selectedDataPoint
$1 = 0x08465ec0 { index=5, x=1325173173.297102, y=122.7664, selected=N }

#7

Hi Kalle,

The delegate method toggledSelectionForPoint returns a copy of the data point so changing properties on it wont actually take effect. You will need to store the index of the selected point and then do the following:

// Get the selected data point (this snippet assumes a single series).
SChartDataPoint *point = [[[[[areaChart chartSeries] objectAtIndex:0] dataSeries] dataPoints] objectAtIndex:selectedPointIndex];
    
// Set the selected property on the selected data point.
point.selected = NO;
    
// Redraw the UI kit elements AND the plot area (GL).
[areaChart redrawChartAndGL:YES];

That should programatically deselect the point :smile:.


#8

Thanks, that fixed  it! It is not very obvious though and I either recommend to add more documentation or to add an API method for it.


#9

I will forward the suggestion directly onto our development team. We are always happy to hear feedback!


#10

Hi Jan,

I have similiar issue with toggledSelectionForPoint called even when not tapping on point. I did set interpolatePoints to NO but it doesn’t help. I am using Version: 2.2.1 (Premium), released on Jun  6 2013. Do you have any idea?

Thank you,
Binh


#11

I agree, this is not obvious and should be fixed.


#12

Thanks for the feedback.

I’ve updated our documentation with a note that ‘redrawChart’ needs to be called on the chart and will also make a note to re-review our selection API.

Kind regards,

Sam