angular-highcharts icon indicating copy to clipboard operation
angular-highcharts copied to clipboard

Question: How to handle highcharts events?

Open attilacsanyi opened this issue 8 years ago • 1 comments

Hi,

Is it possible to register event handlers like legendItemClick or point select events on the tag where [chart] directive ws placed?

Thanks in advance, plunker example would be nice 😉

attilacsanyi avatar Jul 27 '17 14:07 attilacsanyi

Managed to add event handlers above like this:

chart = new Chart({
      chart: {
        type: 'line'
      },
      title: {
        text: 'Linechart'
      },
      credits: {
        enabled: false
      },
      plotOptions : {
        series: {
          cursor: 'pointer', // Clickable chart has pointer cursor
          allowPointSelect: true,
          point: {
            events: {
              select: this.onPointSelect.bind(this),
            }
          },
          events: {
            legendItemClick: this.onLegendItemClick.bind(this),
          },
        }
      }
    });

And you can simply define the two event handlers above in the Angular component like this:

  onPointSelect(event: { target: highcharts.DataPoint }) {
    ...
  }

  onLegendItemClick = (event: { target: highcharts.SeriesObject }) => {
    ...
  }

This is a way it could work ;-)

attilacsanyi avatar Oct 20 '17 15:10 attilacsanyi