How to add a click listener to amCharts bullets in Angular?

231 Views Asked by At

I implemented custom bullets with amCharts and would now like to add a click listener for each bullet with which I can open a popup with detailed information on the respective bullet.

We are currently using amcharts/amcharts3-angular and have set up our configuration accordingly.

My function within my chart service, with which the chart is generated, looks like this (I simplified it for stackoverflow):

  getChart(series, chart, amChart, includeInfos) {
    let colorIndex = 0;

    if (series && series.identifiers.length > 0 && series.values.length > 0) {
      const graphs = [];
      let legend = {};
      chart.anomalies = 0;
      chart.insights = 0;


      series.identifiers.forEach(identifier => {
        if (identifier.includes('_info1')) {
          this.transformInfos1ToBubbles(series, identifier, chart);
          return;
        }
        if (identifier.includes('_info2')) {
          this.transformInfos2ToBubbles(series, identifier, chart);
          return;
        }
        graphs.push({visibleInLegend: false, lineAlpha: 0, valueField: identifier, customBulletField: identifier + '_info1'});

        graphs.push({visibleInLegend: false, lineAlpha: 0, valueField: identifier, customBulletField: identifier + '_info2'});

        graphs.push({
          // some other configuration
          // ...
          // ...
          bullet: 'custom',
          bulletBorderAlpha: 0,
          bulletSize: 10,
          customBullet: '/assets/images/transparent.png',
          hideBulletsCount: 0,
          // some other configuration
          // ...
          // ...
        });
      ...

The "tranformInfos2ToBullets" method looks like this:

  private transformInfos2ToBubbles(data, identifier, chart) {
    for (let j = 0; j < data.values.length; j++) {
      if (data.values[j][identifier]) {
        if (chart) {
          chart.infos2++;
        }
        data.values[j][identifier] = './info1.png';
      }
    }
  }
0

There are 0 best solutions below