score:4
how can I use addSeries() to add series into the existing chart and how can I update the properties of existing chart.
When using highcharts-angular
wrapper it is not recommended to use chart methods like addSeries()
or update()
directly on chart reference.
You have to update a whole component, not only chart properties. It can be achieved by updating chartOptions object (add new series, point, title etc) and setting updateFlag = true
. 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)]="updateFlag"
[oneToOne]="true"
style="width: 100%; height: 400px; display: block;"
>
</highcharts-chart>
<button (click)="updateChart()">Update Chart</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;
updateFlag = false;
Highcharts = Highcharts;
chartConstructor = "chart";
chartCallback;
chartOptions = {
series: [
{
data: [1, 2, 3, 6, 9]
}
],
exporting: {
enabled: true
},
yAxis: {
allowDecimals: false,
title: {
text: "Data"
}
}
};
constructor() {
const self = this;
this.chartCallback = chart => {
// saving chart reference
self.chart = chart;
};
}
ngOnInit() {}
updateChart() {
const self = this,
chart = this.chart;
chart.showLoading();
setTimeout(() => {
chart.hideLoading();
self.chartOptions.series = [
{
data: [10, 25, 15]
},
{
data: [12, 15, 10]
}
];
self.chartOptions.title = {
text: "Updated title!"
};
self.updateFlag = true;
}, 2000);
}
}
Demo:
Docs reference:
score:-1
here is a very useful answer for learning how to updata a highchart.
https://www.highcharts.com/demo/chart-update
it explains a method chart.update
chart.update({
chart: {
inverted: false,
polar: false
},
subtitle: {
text: 'Plain'
}
});
For adding series the following method is used
chart.addSerie(serie,true);
flag 'true' here is equivalent to chart.redraw();
OR
var chart = new Highcharts.Chart(options);
chart.addSeries({
name: array.name,
data: array.value
});
If you are going to add several series you should set the redraw flag to false and then call redraw manually after as that will be much faster.
var chart = new Highcharts.Chart(options);
chart.addSeries({
name: 'Bill',
data: [1,2,4,6]
}, false);
chart.addSeries({
name: 'John',
data: [4,6,4,6]
}, false);
chart.redraw();
For more information and methods you can visit the Official Highcharts API page:
https://api.highcharts.com/class-reference/Highcharts.Chart
When using angular-highcharts wrapper as import { Chart } from 'angular-highcharts';
create charts as below
chart = new Chart({
chart: {
type: 'line'
},
title: {
text: 'Linechart'
},
credits: {
enabled: false
},
series: [
{
name: 'Line 1',
data: [1, 2, 3]
}
]
});
now you can call all API methods on this
Source: stackoverflow.com
Related Query
- How to use add series and update methods in the high chart wrapper for angular?
- How to use for loop array to add series dynamically for line chart
- finding the value in the series object and displaying in the tooltip of the high chart using angular 4
- How to use the tooltip formatter and still display chart color (like it does by default)?
- How do you add text to the bottom center of legend and bottom center of chart under legend?
- In high chart how to add event for label click
- Use single color for all series in the same chart
- How do I reduce the space between title and chart of a High Chart?
- How to show Legends for all the series data in stacked column chart Highcharts?
- How to show open, close, high and low in tooltip when the chart type is 'line' in highstocks?
- How to display the total of the series values for a donut chart in Highcharts?
- How could you supply multiple series to a line chart in R shiny using highcharter package and without hardcoding the series?
- how to add an color picker control to highchart for changing the color of series by user
- How to use click event on Y-axis label in angular Gantt chart High Chart
- Highstock And Highcharts: How I use StockChart and pie chart on the same page
- How to add a vertical plot line in multiple line series and show the tooltip on Plot line in highchart
- How to add multiple series dynamically and update its data dynamically
- How to update the series data of piechart(using highchart) through loop in angular
- How to change the series color and mark after I draw the line chart in highcharts?Does it has databound event?
- How to add different series data for each categories in Stacked Column chart in Highcharts?
- How to make legend labels to bring out the series of a pie chart and not make them disappear when label is clicked in HighCharts?
- how to get each key and value from object in javascript for high chart graph
- How to change the X and Y axis names of Pie chart High Chart?
- How to change the label color of Y-Axis on click in angular Gantt chart High Chart
- how can I use rangeselector and navigation in highcharts in the given code
- HIGHCHARTS - Given a series with UNIX stamps and values pairs for the data, how do I show only the date for the first and last point on xAxis?
- How to add Indicators in High Stock Candle Stick Chart with Angular 5.0?
- Highcharts datalables enabled for one series and one point on the chart via chart function
- How to update the colour of minColor and maxColor when data is changed in high charts' solid gauge in ReactJS?
- How to add series to an empty chart without breaking the plot border in highcharts
More Query from same tag
- Put two Highcharts Charts Side by Side on a Jekyll Blog (beautiful-jekyll)
- Can we control the Zoom Level when we click on the cluster in Highcharts?
- Highcharts data import JSON - formatting
- How to show data between two date range in spline chart of Highcharts?
- Highcharts Bar Extend past MaxValue
- "adaptToUpdatedData: false" in highcharts don`t works if I put series in chart with "addSeries"
- Show only used ticks in Highcharts
- Highcharts lines not being drawn until browser is resized
- Highcharts: Zebra color chart background
- Import CSV to highcharts scatterplot with tooltip populated by point name and x,y values
- How to make Javascript output brackets for an Array of Arrays. (For Highcharts)
- Drill down function in highcharts in case of line charts
- Unable to Dragend Navigator handles in HighStock
- highcharts mapchart: no color shown after reload the graph
- Disable click on datalabel in pie
- Highcharts: negative value in hebrew
- align chart columns left/right
- Highcharts bar and line issue
- highcharts- php/mysql data fetch
- Display datetime including milliseconds
- Highcharts Export Renderer Image - Only SVG visible
- highchart : create stock chart
- Highmaps - how i can have a seperate legend by different report?
- AngularJS ng-repeat freezes browser while HighCharts render
- How to update chart only on unique data in HighCharts
- Highstock Highcharts date time data on Xaxis
- Highcharts redraw and sort data on draggable line graph
- how to pull json data from a server/url and set equal to a variable?
- High-chart Div save as image and save file in server path
- Highcharts show only particular ticks when large number of x-axis ticks