Friday, 21 September 2018

Chart.js: Pie chart legend "onclick" gets overwritten by "options.onclick" if both are present

I have a pie chart that needs to call one function when you click on a segment of the chart and another different one if a label in the legend is clicked. I hoped to achieve this behaviour with the following:

options: {
            responsive: true,
            legend: {
                position: 'right',
                onClick: function (event, elem) {
                    graph_legend_click(elem.text);
                },
            },
            onClick: function (event) {
                graph_click( event);
            }
        }

However in practice, only the second onclick (which calls graph_click( event);) will actually get executed. the legend onClick doesnt work. What can i do to prevent the second onClick from overwriting the first?



from Chart.js: Pie chart legend "onclick" gets overwritten by "options.onclick" if both are present

No comments:

Post a Comment