Search code examples
anychart

AnyChart Resource Chart How to add event listener for activities


In researching the AnyChart documentation for Resource Charts, it seems as though you should be able to add an event listener for Activities, but I have been unable to get it working.

AnyChart Resource Chart demo http://playground.anychart.com/api/7.12.0/core/resource/anychart.core.resource.Activities.labels_get-plain

AnyChart documentation ( specific to Resource Chart Activities ) https://api.anychart.com/7.12.0/anychart.core.resource.Activities#listen

Adding a listener event to the chart itself works as expected, but does not provide any data specific to the individual activity the user clicked.

I need to add the listener event to the Activities object so that when a user selects/clicks a specific activity within the chart, the listener event fires and returns data specific to that activity.

anychart.onDocumentReady(function () {
    var data = getData();

    chart = anychart.resource();
    chart.data(data);

    var currentActivities = chart.activities();

    // this listener event never fires for the activities object
    currentActivities.listen('click', function(e) {
        // expecting to get an event object specific to the activity clicked by user here
    });

    chart.container("container");
    chart.draw();
});

Solution

  • Version 7.13.0 that will be released next Monday/Tuesday will allow this. Here is a preview build:

    chart.listen("pointClick", function(e){
                console.log(e.data);
    })
    

    http://jsfiddle.net/2f2wt553/2/

    Previous versions do not have that.