Clicking on legend items to toggle chart series

I know that there is an option to have checkboxes next to the legend items in order to show/hide the corresponding chart series. I don't like the checkboxes (personal and client preference) so would like to be able to click on the legend text and markers in order to show/hide the series. Additionally, I can't seem to get the checkboxes to work, perhaps because of grouping.


Is this in any way possible?


I managed to use

event.target.textContent

to get the legend text that has been clicked on, and use that to show/hide the corresponding chart series.


However, this doesn't work when clicking on the legend marker.


Anyone able to go one step further?


Thanks

Hello David,


what you want to achieve is possible using the hitTest that you can call from most of the Dundas BI visualizations and controls. The hitTest takes the X and Y coordinates of you click and returns you the element that you clicked on. In the case of the legend the script would look something like this here:


this.control.hitTest(e.originalEvent.offsetX, e.originalEvent.offsetY, e.originalEvent.target);


This will return you an array of all legend items that a user clicked on so in this case just an array with one element. If you then want for example the text of that legend item you could use something like this here:


var item = this.control.hitTest(e.originalEvent.offsetX, e.originalEvent.offsetY, e.originalEvent.target);

var text = item[0].text


This script will work for both the legend item text and the legend item marker.


I hope this is what you were looking for. Let me know if you have any questions about it or if I misunderstood your question :-)


thanks,


Marina

Thanks Marina, I will try this tomorrow.

I did try hitTest but didn't get anywhere, I will try again and report back.

Yup - this worked perfectly. Thanks Marina!