PDA

View Full Version : Deprecated localToData()


kokot-san
11-12-2009, 06:23 AM
We are using the deprecated method localToData() on charts in several
places for selecting/deselecting bars in a chart. To upgrade to IChartElement2.localToData() version I found that the event listeners "mouseOver" and "mouseDown" should be added to the chart's series instead of the chart itself. Then one can use the new method localToData() on class IChartElement2 like this:

IChartElement2(e.currentTarget).localToData(p);

Obviously, this only works when the bar is present in the chart. In my setup the bar disappears after clicking on it. When the user clicks the chart in the same position again, obviously the event does not arrive at the bar series. With the deprecated method I could still get to the data and make it visible again, but how should I do this now?

Thank you,
Andrej

Peter Cowling
11-14-2009, 10:31 AM
Yeah the problem is that the interaction is now tied into the series - rather than the chart as a whole. As you rightly point out, you cannot interact with what is not there.

The only straightforward ways I can think of achieving what you want are:


toggle the alpha, rather than remove the series
give the user an option to restore the series by clicking in a known (and continuously knowable) place i.e. the bottom of the chart/the series label

kokot-san
11-14-2009, 11:28 AM
Thanks for your reply. I understand your suggestions. The thing is we cannot change the current user-interaction.

Is it not possible to find the index of the data when I click in a chart? Supposedly I have a BarChart and click somewhere in the chart, can I not find out at which index on the Y-axis I am clicking? If I can get the index, I can get the data.

Thank you,
Andrej

Peter Cowling
11-14-2009, 12:22 PM
Yes you could:


create an array of the y values (upper limit of the y band)
listen for the mouse click
compare the click point value to the array
use the array value as a key to the series data


And you may need to ensure that nothing happens if the x-value of the clicked point is outside the graph - depends on how/where you implement it really.

Something like that, anyway.

Also, if the number of y-series you have alters, dependant on data changes, things will be more complex - for the obvious reasons...

And if you layer you series data in any way, it will also be difficult to find a good solution - one that makes sense to the user apart from anything else.

kokot-san
11-17-2009, 06:42 AM
Hi Peter,

Thanks for your reply.

Can you explain what you mean with "create an array of the y values (upper limit of the y band)" and maybe roughly how I can do such a thing?

Thank you,
Andrej

Peter Cowling
11-17-2009, 01:25 PM
Can you explain what you mean with "create an array of the y values (upper limit of the y band)" and maybe roughly how I can do such a thing?


Hi Andrej,

So when the user clicks on a point you can extract the 'y' value. You'll then want to match that to the data you assign to as a series in the chart.

Your series will be distributed evenly over the y axis i.e. in a 'band' of y values. If you calculate the upper limit for each of these y bands (*1), you have a value to compare to your y point (i.e. the one derived from the mouse click).

(*1) calculating the values to assign to an array is just a case of dividing the total y axis pixels by the number of series. This gives you your band value. The upper limit of the first band is the same as the band value. The second, band * 2 etc.

kokot-san
11-18-2009, 06:09 AM
Hi Peter,

Thank you once again.

I follow all that, but how can I get the upper and lower Y-coordinate of the Y-axis with respect to it's chart coordinates? If I can get this information, then the rest follows as you described. How do I get these Y-coordinates?

Cheers,
Andrej

Peter Cowling
11-20-2009, 01:13 PM
Hi Peter,

Thank you once again.

I follow all that, but how can I get the upper and lower Y-coordinate of the Y-axis with respect to it's chart coordinates? If I can get this information, then the rest follows as you described. How do I get these Y-coordinates?

Cheers,
Andrej

Apols for the late reply. If you swap around where I was talking about the Y axis, and replace that with the X Axis, it should make more sense - sorry I have had had a cold, which seems to have affected my concentration somewhat.

So to recap:


capture the mouse cusror X position/point via user click.
calculate the x value of the right hand side of every series on the graph
compare the click point to these values
use the resulting array value to the data which feeds your graph series.

kokot-san
11-20-2009, 01:22 PM
Hi Peter!

Thank you once more.

Unfortunately I was not clear enough. I understand the method, but I do not know how to "calculate the x value of the right hand side of every series on the graph". If you have time, could explain me how to do this? How can I calculate the "band" coordinates so I can map mouse click coordinates in the chart to the series?

Thank you,
Andrej

Peter Cowling
11-20-2009, 01:26 PM
It'll be best to draw a picture. I will do so, and give you are link to it.

Peter Cowling
11-20-2009, 02:05 PM
Hi,

PM'd you with a link to the image.