-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #381 from highcharts/bugfix/chartInstance-emitter
bugfix/chartInstance-emitter
- Loading branch information
Showing
4 changed files
with
71 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
<h2>Demo #1: Highcharts with a basic editor</h2> | ||
<article> | ||
<section> | ||
<textarea rows="16" cols="50" | ||
[(ngModel)]="optFromInputString" | ||
></textarea> | ||
<textarea rows="16" cols="50" [(ngModel)]="optFromInputString"></textarea> | ||
<div class="buttons-wrapper"> | ||
<button (click)="updateInputChart()">Update chart</button> | ||
<button (click)="toggleSeriesType()">1st series type toggle</button> | ||
<button [disabled]="!showChart" (click)="updateInputChart()">Update chart</button> | ||
<button [disabled]="!showChart" (click)="toggleSeriesType()">1st series type toggle</button> | ||
<button (click)="toggleChart()">{{ toggleButtonTitle }}</button> | ||
</div> | ||
</section> | ||
<highcharts-chart | ||
<highcharts-chart | ||
*ngIf="showChart" | ||
[Highcharts]="Highcharts" | ||
[options]="optFromInput" | ||
[(update)]="updateFromInput" | ||
[oneToOne]=true | ||
[oneToOne]="true" | ||
(chartInstance)="logChartInstance($event)" | ||
></highcharts-chart> | ||
</article> | ||
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,67 @@ | ||
import { Component } from '@angular/core'; | ||
import * as Highcharts from 'highcharts'; | ||
import HC_customEvents from 'highcharts-custom-events'; | ||
import { Component } from "@angular/core"; | ||
import * as Highcharts from "highcharts"; | ||
import HC_customEvents from "highcharts-custom-events"; | ||
HC_customEvents(Highcharts); | ||
|
||
@Component({ | ||
selector: 'app-line-chart', | ||
templateUrl: './line-chart.component.html', | ||
styleUrls: ['./line-chart.component.css'] | ||
selector: "app-line-chart", | ||
templateUrl: "./line-chart.component.html", | ||
styleUrls: ["./line-chart.component.css"], | ||
}) | ||
export class LineChartComponent { | ||
Highcharts: typeof Highcharts = Highcharts; // Highcharts, it's Highcharts | ||
public Highcharts: typeof Highcharts = Highcharts; | ||
public updateFromInput = false; | ||
public showChart = true; | ||
public toggleButtonTitle = "Destroy chart"; | ||
|
||
optFromInputString: string = ` | ||
{ | ||
"title": { "text": "Highcharts chart" }, | ||
"series": [{ | ||
"data": [11,2,3], | ||
"zones": [{ | ||
"value": 7.2, | ||
"dashStyle": "dot", | ||
"color": "red" | ||
private optFromInputString = ` | ||
{ | ||
"title": { "text": "Highcharts chart" }, | ||
"series": [{ | ||
"data": [11,2,3], | ||
"zones": [{ | ||
"value": 7.2, | ||
"dashStyle": "dot", | ||
"color": "red" | ||
}] | ||
}, { | ||
"data": [5,6,7] | ||
}] | ||
}, { | ||
"data": [5,6,7] | ||
}] | ||
} | ||
} | ||
`; | ||
private optFromInput: Highcharts.Options = JSON.parse( | ||
this.optFromInputString, | ||
); | ||
private seriesTypes = { | ||
line: "column", | ||
column: "scatter", | ||
scatter: "spline", | ||
spline: "line", | ||
}; | ||
|
||
optFromInput: Highcharts.Options = JSON.parse(this.optFromInputString); | ||
updateFromInput: boolean = false; | ||
// Demonstrate chart instance | ||
public logChartInstance(chart: Highcharts.Chart) { | ||
if (chart) { | ||
console.log("Chart instance received:", chart); | ||
} else { | ||
console.log("Chart instance destroyed"); | ||
} | ||
} | ||
|
||
// Demonstrate chart instance | ||
logChartInstance(chart: Highcharts.Chart) { | ||
console.log('Chart instance: ', chart); | ||
} | ||
|
||
updateInputChart() { | ||
this.optFromInput = JSON.parse(this.optFromInputString); | ||
} | ||
|
||
seriesTypes: {[key: string]: string} = { | ||
line: 'column', | ||
column: 'scatter', | ||
scatter: 'spline', | ||
spline: 'line' | ||
}; | ||
|
||
toggleSeriesType(index: number = 0) { | ||
this.optFromInput.series[index].type = | ||
this.seriesTypes[this.optFromInput.series[index].type || 'line'] as | ||
'column' | 'scatter' | 'spline' | 'line'; | ||
// nested change - must trigger update | ||
this.updateFromInput = true; | ||
} | ||
public updateInputChart() { | ||
this.optFromInput = JSON.parse(this.optFromInputString); | ||
} | ||
|
||
public toggleSeriesType(index = 0) { | ||
this.optFromInput.series[index].type = this.seriesTypes[ | ||
this.optFromInput.series[index].type || "line" | ||
] as keyof typeof this.seriesTypes; | ||
// nested change - must trigger update | ||
this.updateFromInput = true; | ||
} | ||
|
||
public toggleChart() { | ||
this.showChart = !this.showChart; | ||
this.toggleButtonTitle = this.showChart ? "Destroy chart" : "Recreate chart"; | ||
} | ||
} |