score:1
Unfortunately, I have no idea why Angular throwing that error. Could you attach the content of this.chart.legend
object?
However, I suggest you use official Highcharts wrapper for Angular (that can be downloaded here: https://github.com/highcharts/highcharts-angular) because updating chart beyond the Angular framework is not recommended. Then you can just change chart options with changed legend name and change the updateFromInput
flag to update the whole chart component. Check the code and demo posted below.
app.module.ts :
import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { HighchartsChartModule } from "highcharts-angular";
import { ChartComponent } from "./chart.component";
import { AppComponent } from "./app.component";
@NgModule({
declarations: [AppComponent, ChartComponent],
imports: [BrowserModule, HighchartsChartModule],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
chart.component.html :
<div class="boxChart__container">
<div>
<highcharts-chart
id="container"
[Highcharts]="Highcharts"
[constructorType]="chartConstructor"
[options]="chartOptions"
[callbackFunction]="chartCallback"
[(update)]="updateFromInput"
[oneToOne]="true"
style="width: 100%; height: 400px; display: block;"
>
</highcharts-chart>
<button (click)="update_chart()">Change legend name</button>
</div>
</div>
chart.component.ts:
import { Component, OnInit } from "@angular/core";
import * as Highcharts from "highcharts";
import * as HighchartsMore from "highcharts/highcharts-more";
import * as HighchartsExporting from "highcharts/modules/exporting";
HighchartsMore(Highcharts);
HighchartsExporting(Highcharts);
@Component({
selector: "app-chart",
templateUrl: "./chart.component.html"
})
export class ChartComponent implements OnInit {
title = "app";
chart;
updateFromInput = false;
Highcharts = Highcharts;
chartConstructor = "chart";
chartCallback;
chartOptions = {
series: [
{
name: "Series name",
data: [1, 2, 3, 6, 9]
}
],
exporting: {
enabled: true
},
yAxis: {
allowDecimals: false,
title: {
text: "Data"
}
}
};
constructor() {
const self = this;
this.chartCallback = chart => {
self.chart = chart;
};
}
ngOnInit() {}
update_chart() {
const self = this,
chart = this.chart;
self.chartOptions.legend = {
labelFormatter: function() {
return `${this.name} - edited`;
}
};
self.updateFromInput = true;
}
}
Demo:
https://codesandbox.io/s/7y5j93l2rq
Highcharts Angular wrapper:
https://github.com/highcharts/highcharts-angular
Source: stackoverflow.com
Related Query
- HighCharts does not recognize a function of Legend
- Highcharts custom legend SVG symbol does not fade when you click to turn off series
- Highcharts tooltip formatter function does not display values in table correct
- How to modify the code so that Highcharts graph does not cover fixed navigation bar at the top of the page?
- Highcharts (highstock.js) exporting function does not work on Embedded Visualforce pages
- Does highcharts have a callback function for before full chart reload (this should not include legends disable)?
- Highcharts Legend 'enabled' function not working
- Highcharts code with same set of code/data works in PHP but does not work in JSfiddle
- Javascript/jQuery plug-in Highcharts does not recognize my data array. Is it my syntax?
- Highcharts :Uncaught TypeError: $(...).highcharts is not a function
- Highcharts does not resize charts inside tabs
- Highcharts saying undefined is not a function when trying to add a new chart
- Highcharts does not work with wicked_pdf
- Uncaught TypeError: e.doDrilldown is not a function - Highcharts
- Uncaught TypeError: undefined is not a function - Highcharts - MVC
- HighCharts TypeError: ha is not a function
- Highcharts reflow does not work on class selector
- Area range legend icon does not match marker
- HighCharts error #18: Requested Axis Does not exist
- Uncaught TypeError: undefined is not a function when using highcharts
- Legend and Axis titles not showing in Highcharts Graph
- Legend and Axis titles not showing in Highcharts Graph
- HighCharts chart export (screenshot download) does not display Navigator graph
- wkhtmltoimage does not show gridlines of highcharts graph
- Highcharts legend title border not full width
- Second yAxis does not scale according to series in Highcharts
- Customise Highcharts Pie Chart Selection State so that slice does not animate out when selected
- Highcharts solidgauge legend symbol not taking series color
- Highcharts add a serie that does not exist
- Highcharts export menu does not show up fully
More Query from same tag
- Onclick download the highchart
- Highcharts with Angular
- How to boost your performance in HighCharts
- Highcharts How to display total of data classes in legend
- How to use high charts donut charts in Angular
- Highcharts grouping column, hide in tooltip
- Highcharts: How to disable piechart tooltip in combination chart example
- Overlap bars in highchart's columnrange plot
- highcharts example for using data from database with mvc
- Highcharts marker size change on/after hover
- Highchart how to animate from the xaxis bottom line upward
- Effective way to display the data in the chart
- Combining graphs in highcharts
- Use return data from dynamic highcharts chart in Shiny
- Including source for Alchemy js breaks Highcharts js
- Display percentage on tooltip highchart Angular 2
- Custom legend in rCharts (highcharts)
- Rails 3: Creating compact array for highcharts includes nil, but shouldn't
- Combine bullet and line chart in highcharts
- (kendoUI chart) Possible to reflow its size with a resizing window?
- Highcharts.js - Switch label axis and hiding legend
- "Highcarts is not defined error" after installing highcharts
- HighCharts: How to pass x and y value of selected point to Rails
- Highcharts - Multiple Y axis
- Click event for bar-chart using Highcharts not working?
- Best way for debugging Hover state with CSS and JS changes
- Angular Highchart - Set Timezone
- Highcharts, stop the rendering of dynamic spline graph
- Error: Highcharts error #13 ionic angular
- stockChart is not defined(…)