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

Message ListMessage List     Post MessagePost Message

  Set up the MouseMovePlotArea event handler for multiple charts (ASP.Net)
Posted by VKotaidis on Apr-26-2020 19:54
How to adjust the JsChartViewer.addEventListener function to enable track box for an array of viewers?

  Re: Set up the MouseMovePlotArea event handler for multiple charts (ASP.Net)
Posted by Peter Kwan on Apr-27-2020 17:55
VKotaidis wrote:

How to adjust the JsChartViewer.addEventListener function to enable track box for an array of viewers?

  Re: Set up the MouseMovePlotArea event handler for multiple charts (ASP.Net)
Posted by Peter Kwan on Apr-27-2020 18:05
Hi Vkotaidis,

As you mentioned "track box", I will use the "Track Box with Floating Legend" as an example.

JsChartViewer.addEventListener(window, 'load', function() {

    var allViewers = [ ... an array of viewer IDs ... ];

    for (var i = 0; i < allViewers.length; ++i)
    {
        var viewer = JsChartViewer.get(allViewers[i]);

        // Draw track cursor when mouse is moving over plotarea. Hide it when mouse leaves plot area.
        viewer.attachHandler(["MouseMovePlotArea", "TouchStartPlotArea", "TouchMovePlotArea", "ChartMove"],
        function(e) {
            this.preventDefault(e);   // Prevent the browser from using touch events for other actions
            trackBoxLegend(this, this.getPlotAreaMouseX(), this.getPlotAreaMouseY());
            this.setAutoHide("all", ["MouseOutPlotArea", "TouchEndPlotArea"]);
        });
    }
});


So basically, I just all a "for" loop to iterate through all the viewer IDs. For the code inside "function(e)", originally it is using the "viewer" object for some code, but I change it to using the "this" object. They are the same if there is only one viewer, but for multiple viewers, we need to specifically refers to the viewer that triggers the events, which is "this".

Regards
Peter Kwan

  Re: Set up the MouseMovePlotArea event handler for multiple charts (ASP.Net)
Posted by VKotaidis on Apr-28-2020 02:58
Peter, many thanks for your answer! Problem solved.
Vassili