highcharts-angular dynamically update from DB
up vote
0
down vote
favorite
I'm using highcharts-angular in angular 6 app.
When I set data, hardcore it, in ngOnInit, chart is visible and works correctly.
But I want to update chart series dynamically, meaning add point to the series, add new series...
This will be done after calling web API and getting new data, calling loadBidChartData().
If I set new series for chat, or update series, chart don't see changes, initial state is not changing.
How can I solve this?
Here is small peace of example code
in html is like this:
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [update]="true" ></highcharts-chart>
in angular:
import * as Highcharts from 'highcharts';
export class ExampleComponent implements OnInit {
Highcharts = Highcharts; // required
chartOptions = {
chart: {
type: "scatter",
width: 900
},
},
tooltip: {
valueDecimals: 0,
formatter: function () {
return this.y + ' €';
}
},
title: {
text: ''
},
xAxis: {
type: 'datetime',
},
yAxis: {
type: 'number',
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
floating: false,
borderWidth: 1
},
series:
};
ngOnInit(): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
}];
}
loadBidChartData(bidApiModel: BidItem): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
}
}
Solution:
Working demo with updating in background and adding and removing points to highcharts: https://stackblitz.com/edit/angular-bv26xz
Thank you User3250 and Wojciech Chmiel for the help.
angular highcharts
add a comment |
up vote
0
down vote
favorite
I'm using highcharts-angular in angular 6 app.
When I set data, hardcore it, in ngOnInit, chart is visible and works correctly.
But I want to update chart series dynamically, meaning add point to the series, add new series...
This will be done after calling web API and getting new data, calling loadBidChartData().
If I set new series for chat, or update series, chart don't see changes, initial state is not changing.
How can I solve this?
Here is small peace of example code
in html is like this:
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [update]="true" ></highcharts-chart>
in angular:
import * as Highcharts from 'highcharts';
export class ExampleComponent implements OnInit {
Highcharts = Highcharts; // required
chartOptions = {
chart: {
type: "scatter",
width: 900
},
},
tooltip: {
valueDecimals: 0,
formatter: function () {
return this.y + ' €';
}
},
title: {
text: ''
},
xAxis: {
type: 'datetime',
},
yAxis: {
type: 'number',
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
floating: false,
borderWidth: 1
},
series:
};
ngOnInit(): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
}];
}
loadBidChartData(bidApiModel: BidItem): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
}
}
Solution:
Working demo with updating in background and adding and removing points to highcharts: https://stackblitz.com/edit/angular-bv26xz
Thank you User3250 and Wojciech Chmiel for the help.
angular highcharts
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm using highcharts-angular in angular 6 app.
When I set data, hardcore it, in ngOnInit, chart is visible and works correctly.
But I want to update chart series dynamically, meaning add point to the series, add new series...
This will be done after calling web API and getting new data, calling loadBidChartData().
If I set new series for chat, or update series, chart don't see changes, initial state is not changing.
How can I solve this?
Here is small peace of example code
in html is like this:
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [update]="true" ></highcharts-chart>
in angular:
import * as Highcharts from 'highcharts';
export class ExampleComponent implements OnInit {
Highcharts = Highcharts; // required
chartOptions = {
chart: {
type: "scatter",
width: 900
},
},
tooltip: {
valueDecimals: 0,
formatter: function () {
return this.y + ' €';
}
},
title: {
text: ''
},
xAxis: {
type: 'datetime',
},
yAxis: {
type: 'number',
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
floating: false,
borderWidth: 1
},
series:
};
ngOnInit(): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
}];
}
loadBidChartData(bidApiModel: BidItem): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
}
}
Solution:
Working demo with updating in background and adding and removing points to highcharts: https://stackblitz.com/edit/angular-bv26xz
Thank you User3250 and Wojciech Chmiel for the help.
angular highcharts
I'm using highcharts-angular in angular 6 app.
When I set data, hardcore it, in ngOnInit, chart is visible and works correctly.
But I want to update chart series dynamically, meaning add point to the series, add new series...
This will be done after calling web API and getting new data, calling loadBidChartData().
If I set new series for chat, or update series, chart don't see changes, initial state is not changing.
How can I solve this?
Here is small peace of example code
in html is like this:
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [update]="true" ></highcharts-chart>
in angular:
import * as Highcharts from 'highcharts';
export class ExampleComponent implements OnInit {
Highcharts = Highcharts; // required
chartOptions = {
chart: {
type: "scatter",
width: 900
},
},
tooltip: {
valueDecimals: 0,
formatter: function () {
return this.y + ' €';
}
},
title: {
text: ''
},
xAxis: {
type: 'datetime',
},
yAxis: {
type: 'number',
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
floating: false,
borderWidth: 1
},
series:
};
ngOnInit(): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
}];
}
loadBidChartData(bidApiModel: BidItem): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
}
}
Solution:
Working demo with updating in background and adding and removing points to highcharts: https://stackblitz.com/edit/angular-bv26xz
Thank you User3250 and Wojciech Chmiel for the help.
angular highcharts
angular highcharts
edited Nov 20 at 9:29
asked Nov 19 at 12:39
user1698635
358
358
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You need to use [(update)]
flag to update the series as below:
loadBidChartData(bidApiModel: BidItem): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
this.updateFlag = true;
}
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [(update)]="updateFlag" ></highcharts-chart>
Working demo here: https://stackblitz.com/edit/angular-d5spve
2
Check also this demo with an update: codesandbox.io/s/543l0p0qq4
– Wojciech Chmiel
Nov 20 at 7:17
1
Thank you for the demo with update Wojciech Chmiel
– user1698635
Nov 20 at 7:27
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You need to use [(update)]
flag to update the series as below:
loadBidChartData(bidApiModel: BidItem): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
this.updateFlag = true;
}
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [(update)]="updateFlag" ></highcharts-chart>
Working demo here: https://stackblitz.com/edit/angular-d5spve
2
Check also this demo with an update: codesandbox.io/s/543l0p0qq4
– Wojciech Chmiel
Nov 20 at 7:17
1
Thank you for the demo with update Wojciech Chmiel
– user1698635
Nov 20 at 7:27
add a comment |
up vote
1
down vote
accepted
You need to use [(update)]
flag to update the series as below:
loadBidChartData(bidApiModel: BidItem): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
this.updateFlag = true;
}
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [(update)]="updateFlag" ></highcharts-chart>
Working demo here: https://stackblitz.com/edit/angular-d5spve
2
Check also this demo with an update: codesandbox.io/s/543l0p0qq4
– Wojciech Chmiel
Nov 20 at 7:17
1
Thank you for the demo with update Wojciech Chmiel
– user1698635
Nov 20 at 7:27
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You need to use [(update)]
flag to update the series as below:
loadBidChartData(bidApiModel: BidItem): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
this.updateFlag = true;
}
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [(update)]="updateFlag" ></highcharts-chart>
Working demo here: https://stackblitz.com/edit/angular-d5spve
You need to use [(update)]
flag to update the series as below:
loadBidChartData(bidApiModel: BidItem): void {
this.chartOptions.series= [{
name: 'first last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 25), 23], [Date.UTC(2018, 11, 16, 10, 57, 15), 132], [Date.UTC(2018, 11, 16, 10, 58, 2), 312], [Date.UTC(2018, 11, 16, 10, 58, 15), 432]]
},
{
name: 'second last',
data: [[Date.UTC(2018, 11, 16, 10, 56, 28), 50], [Date.UTC(2018, 11, 16, 10, 56, 45), 152], [Date.UTC(2018, 11, 16, 10, 56, 53), 250], [Date.UTC(2018, 11, 16, 10, 57, 11), 320]]
}];
this.updateFlag = true;
}
<highcharts-chart [Highcharts]="Highcharts" [options]="chartOptions" style="width: 100%; height: 400px; display: block; overflow: auto;" [(update)]="updateFlag" ></highcharts-chart>
Working demo here: https://stackblitz.com/edit/angular-d5spve
answered Nov 19 at 14:46
User3250
1,5533825
1,5533825
2
Check also this demo with an update: codesandbox.io/s/543l0p0qq4
– Wojciech Chmiel
Nov 20 at 7:17
1
Thank you for the demo with update Wojciech Chmiel
– user1698635
Nov 20 at 7:27
add a comment |
2
Check also this demo with an update: codesandbox.io/s/543l0p0qq4
– Wojciech Chmiel
Nov 20 at 7:17
1
Thank you for the demo with update Wojciech Chmiel
– user1698635
Nov 20 at 7:27
2
2
Check also this demo with an update: codesandbox.io/s/543l0p0qq4
– Wojciech Chmiel
Nov 20 at 7:17
Check also this demo with an update: codesandbox.io/s/543l0p0qq4
– Wojciech Chmiel
Nov 20 at 7:17
1
1
Thank you for the demo with update Wojciech Chmiel
– user1698635
Nov 20 at 7:27
Thank you for the demo with update Wojciech Chmiel
– user1698635
Nov 20 at 7:27
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374858%2fhighcharts-angular-dynamically-update-from-db%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown