3

I have used https://github.com/highcharts/highcharts-angular this official wrapper and try to call the callback function to get the chart object. Unfortunately, though I tried various methods that did not give any proper results as I expect. Also, there aren't many documents that describe the callback function. Can someone let me know how to use the callback function?

2 Answers 2

4

The callback didn't work for me either. I was inspecting the code source and I saw the @Output event emitter called chartInstance... It is also documented:

component output chartInstance - emitted after chart is created (see demo app and logChartInstance function)

So I've used as a normal output event binding:

<highcharts-chart
 [Highcharts]="Highcharts"
 [options]="chartOptions"
 ...
 (chartInstance)="onChartInstance($event)"
 ...
></highcharts-chart>

And voilà... I think that is not a definitive solution but as a temporary workaround it works pretty well for me.

1
  • As default 'this' in the callback function points to the chart, I also use 'chartInstance' to assign chart instance to my component variable. Commented Apr 5, 2024 at 4:43
0

It can be achieved in two steps:

  1. Add [callbackFunction]="chartCallback" in compontent's HTML file (just as presented in the documentation):
 <highcharts-chart
   style="width: 100%; display: block"
   [Highcharts]="Highcharts"
   [options]="chartOptions"
   [(update)]="updateDemo"
   [callbackFunction]="chartCallback"
   [runOutsideAngular]="true"
 >
 </highcharts-chart>
  1. Initialize callback in the component's TS:
  chartCallback: Function = function(chart) {
    console.log("Chart instance: ", chart);
  };

Live demo: https://codesandbox.io/s/angular-b5420

Documentation for the callback (third argument of chart's constructor).

3
  • 1
    I tried this way but it did not show actual results
    – Chandana
    Commented Mar 20, 2020 at 14:49
  • Please provide a live demo that recreates your case. You can fork my codesanbox demo and use it as a template. Commented Mar 23, 2020 at 6:46
  • This method worked great for us until we updated our Angular Version. We went from v8 to v13 so I'm not sure which version caused the callback to "break."
    – Mark
    Commented Jul 26, 2022 at 17:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.