ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Individual Clickable Track Line Legend Entries
Posted by Sherri on Jun-14-2016 10:08
I'm having trouble figuring out how to make individual entries in the track line legend clickable.  I would like to be able to hide and show dataset layers when the legend entry is clicked.

I'm using the PHP version of ChartDirector.  Any suggestions would be greatly appreciated.

  Re: Individual Clickable Track Line Legend Entries
Posted by Peter Kwan on Jun-15-2016 04:42
Hi Sherri,

There is a similar example in the "Zooming and Scrolling with Track Line" sample code:

http://www.advsofteng.com/doc/cdphp.htm#zoomscrolltrackweb.htm

In the above sample code, there is "track line legend", and there are check boxes to enable and disable lines.

If you would like to use the legend items instead, please modify the legend item text to include an "onclick" event (eg. by adding a <span> tag with onclick). In the event handler, you can use Javascript to toggle the "check boxes" and update the chart (by executing the code that would be run when the button is pushed). The "check boxes" can be hidden in some invisible places or be replaced with <input type="hidden" ...> fields.

Regards
Peter Kwan

  Re: Individual Clickable Track Line Legend Entries
Posted by Sherri on Jun-15-2016 05:08
Worked like a champ!!  Thanks so much Peter!

  Re: Individual Clickable Track Line Legend Entries
Posted by Richard on Aug-03-2016 15:48
Hi Peter,
I too am interested in showing/hiding series by clicking the legend, but my javascript and html skills don't seem to be up to it. When you say to add a <span> tag with an onclick event, could you please provide an example of it. What I'm using is not working in the provided example...

// Build the legend entry, consist of a colored square box, the name and the data value.
            var dataValue = dataSet.getValue(xIndex);
            legendEntries.push("<span>onclick="ShowHide();"</span> <nobr>" + viewer.htmlRect(7, 7, color) + " " + dataName + ": " +
                ((dataValue == null) ? "N/A" : dataValue.toPrecision(4)) + viewer.htmlRect(20, 0) + "</nobr> ");

Thanks,
Richard

  Re: Individual Clickable Track Line Legend Entries
Posted by Peter Kwan on Aug-04-2016 00:15
Hi Richard,

The onclick even should be added like:

legendEntries.push("<span onclick='alert(1);'><nobr>" + viewer.htmlRect(7, 7, color) + " " + dataName + ": " +
                ((dataValue == null) ? "N/A" : dataValue.toPrecision(4)) + viewer.htmlRect(20, 0) + "</nobr></span> ");

Also, in the same code, the legend box is added with showTextBox, like:

viewer.showTextBox("legend", ....);

Please change the above to:

viewer.showClickableTextBox("legend", ....);

Note that in the sample code, the legend box is built based on the data in the chart. If you hide a data series, the legend box will not show the data series, so there is no legend entry for your to click to show the data series. You may need to modify the code so that the legend box is not related to the chart data, that is, the legend entries exists regardless of what is on the chart. In this way, the user would have something to click on to show a data series.

Regards
Peter Kwan

  Re: Individual Clickable Track Line Legend Entries
Posted by Richard on Aug-04-2016 15:44
Thanks again Peter.