Add custom buttons in Angular Highcharts Line Chart

Viewed 842

I'm trying to add 2 custom buttons in Angular Highcharts Line chart in the exporting property

exporting: {
    enabled: true,
    buttons: {
        customButton: {
            text: 'Custom Button',
            click: () => {
                alert('You pressed the button!');
            },
        },
        anotherButton: {
            text: 'Another Button',
            click: () => {
                alert('You pressed another button!');
            },
        },
    },
}

But these 2 buttons not displaying. What could be the missing logic here? Stackblitz

2 Answers

Hi think the below snippet will help you:

chart: {
  type: "line",
  renderTo: "chart",
  events: {
    render(events) {
      let chart = this;

      if (chart.customButton) {
        chart.customButton.destroy();
      }
      chart.customButton = chart.renderer
        .button("custom button", 100, 40, () => {
          console.log("clicked.....");
          chart.exportChart({
            type: "application/pdf",
            filename: "line-chart"
          });
        })
        .add();
    }
  }
}

Here on click the button, you can implement the export. The example here exports PDF.

Demo:

https://stackblitz.com/edit/highcharts-angular-functionality?file=src%2Fapp%2Fstackoverflow%2Fhigh-chart-question%2Fhigh-chart-question.component.ts

https://highcharts-angular-functionality.stackblitz.io/exportcolor

Hope this helps.

Related