-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chart create and destroy #218
Comments
Hi @EoleDev, thanks for reaching out to us! To make it work you could save the chart reference and then use it to call the For the future, for general tech support, please see www.highcharts.com/support. Live demo: export class AppComponent {
Highcharts: typeof Highcharts = Highcharts;
chartRef: Highcharts.Chart;
chartOptions: Options = {
series: [
{
type: "line",
data: [1, 2, 3]
}
]
};
chartCallback: Highcharts.ChartCallbackFunction = (chart) => {
this.chartRef = chart;
};
handleClick():void {
this.chartRef.destroy();
}
} |
Thanks for your quick answer @mateuszkornecki I tried to use the reference and call the destroy function but as I can't recreate the chart, The main problem is :
When it call the function, as the reference on chart is not destroyed, the first condition is fulfilled and it try to If you have a solution, It would be a great help :) |
Then you could try another approach. You can create a ref to the References: Live example: <highcharts-chart
#chart
[Highcharts]="Highcharts"
[options]="chartOptions"
[update]="updateFlag"
></highcharts-chart>
<button (click)="destroyChart()">Destroy chart</button>
<button (click)="createChart()">Create chart</button> import { Component, ViewChild } from "@angular/core";
import * as Highcharts from 'highcharts';
import { Options } from "highcharts";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
Highcharts: typeof Highcharts = Highcharts;
@ViewChild('chart') chartRef;
updateFlag;
chartOptions: Options = {
series: [
{
type: "line",
data: [1, 2, 3]
}
]
};
createChart():void {
this.updateFlag = true;
}
destroyChart():void {
this.chartRef.ngOnDestroy();
}
} |
Hi @mateuszkornecki, Unfortunately, it doesn't bring a solution to my problem. In your example, if you destroy, create and destroy again the chart you are not Thanks again! |
Then let's combine both solutions - destroy the chart using chart reference from the callback function (no the component one), and reset the component's chart object to allow chart's recreation. The highcharts-angular wrapper was build to be a lightweight component (it has literally just a few methods). It might be a good idea for enhancement if more users will request adding that functionality. Live demo: export class AppComponent {
Highcharts: typeof Highcharts = Highcharts;
@ViewChild('chart') componentRef;
chartRef;
updateFlag;
chartOptions: Options = {
series: [
{
type: "line",
data: [1, 2, 3]
}
]
};
chartCallback: Highcharts.ChartCallbackFunction = (chart) => {
this.chartRef = chart;
};
createChart():void {
this.updateFlag = true;
}
destroyChart():void {
this.chartRef.destroy();
this.componentRef.chart = null;
}
} |
Hi @mateuszkornecki, With the current live demo, things are not working quite well. Changes :
In case the chart is not recreated, we don't try to destroy a previously destroyed chart. This solution allow to destroy and recreate chart. Thanks for all! |
Hi,
Thanks for your work!
We are currently having a problem,
we have a chart on a component with some route parameters.
When the parameters are changing, we can't reset the chart in a simple way.
Would you be able, to add an API call to create and destroy the chart ?
Thank you very much!
The text was updated successfully, but these errors were encountered: