Reputation: 254
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
Upvotes: 3
Views: 1458
Reputation: 1040
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://highcharts-angular-functionality.stackblitz.io/exportcolor
Hope this helps.
Upvotes: 2
Reputation: 11633
The exporting.buttons is an option to edit the buttons in the exporting menu only: https://api.highcharts.com/highcharts/exporting.buttons
To render the custom buttons use the SVGRenderer feature: https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#button
You can add those buttons in the render callback - calls after initial load and after each redraw: https://api.highcharts.com/highcharts/chart.events.render
Upvotes: 1