Primeng Charts
-
- Posts: 11
- Joined: 15 Mar 2017, 10:31
How to refresh chart after data has changed . Currently data is changed but chart does not refresh. Any possible ways to redraw the chart manually will also be helpful.Any Solutions? Thanx in advance
it is easy:Saurav Dubey wrote: ↑22 Mar 2017, 11:31How to refresh chart after data has changed . Currently data is changed but chart does not refresh. Any possible ways to redraw the chart manually will also be helpful.Any Solutions? Thanx in advance
html:
Code: Select all
<p-chart #chart type="bar" [options]="yourOptions" [data]="yourData" </p-chart>
Code: Select all
import { Component, ViewChild } from '@angular/core';
import { UIChart } from 'primeng/primeng';
@ViewChild('chart') chart: UIChart;
function(){
this.chart.refresh();
}
-
- Posts: 11
- Joined: 15 Mar 2017, 10:31
-
- Posts: 11
- Joined: 15 Mar 2017, 10:31
this is not working chart:UIChart remains undefined and hence cant access refresh. Can you share your code maybe I am doing something wrongalexey93 wrote: ↑22 Mar 2017, 13:29
it is easy:
html:ts:Code: Select all
<p-chart #chart type="bar" [options]="yourOptions" [data]="yourData" </p-chart>
this will work with primeng 2.0.x I believe. In erlier versions you would call this.chart.update();Code: Select all
import { Component, ViewChild } from '@angular/core'; import { UIChart } from 'primeng/primeng'; @ViewChild('chart') chart: UIChart; function(){ this.chart.refresh(); }
Saurav Dubey wrote: ↑23 Mar 2017, 07:49
this is not working chart:UIChart remains undefined and hence cant access refresh. Can you share your code maybe I am doing something wrong
Code: Select all
setTimeout(function () { chart.refresh() }, 1000);
-
- Posts: 11
- Joined: 15 Mar 2017, 10:31
if i use setTimeout den i can just hide and unhide div and the chart will redraw.alexey93 wrote: ↑23 Mar 2017, 09:11
try it like this than. The code you see above is my code, and it is working like this.Code: Select all
setTimeout(function () { chart.refresh() }, 1000);
Code: Select all
setTimeout(() => {
this.initial = true;
}, 1000);
Do you have any sample for "chart.initChart()".
Did you try to read the docs at all?Saurav Dubey wrote: ↑23 Mar 2017, 09:21
if i use setTimeout den i can just hide and unhide div and the chart will redraw.this works just fine. initial is my *ngIf variable.Code: Select all
setTimeout(() => { this.initial = true; }, 1000);
Do you have any sample for "chart.initChart()".
https://www.primefaces.org/primeng/#/chart
For me it works without a timeout, I had the problem only if I didnt initalize the graph with some random data. And this way is much easier, than redrwaing the whole div everytime. You can set the timeout on just 0.1 seconds, and it should work just fine as well.Methods
Name Parameters Description
refresh - Redraws the graph with new data.
reinit - Destroys the graph first and then creates it again.
that is how I initiliaze my graphs for now.
Code: Select all
ngOnInit() {
this.ProfileService.getProfiles().then(profiles => this.profiles = profiles)
.then(() => {
this.update_bar_charts();
this.update_dognutcharts();
this.chart.refresh();
this.chart2.refresh();
});
}
-
- Posts: 11
- Joined: 15 Mar 2017, 10:31
I have read the documentation. Using inside ngOnInit u dont need chart.refresh(). your chart is displayed just by initialising the data.alexey93 wrote: ↑23 Mar 2017, 10:52Did you try to read the docs at all?Saurav Dubey wrote: ↑23 Mar 2017, 09:21
if i use setTimeout den i can just hide and unhide div and the chart will redraw.this works just fine. initial is my *ngIf variable.Code: Select all
setTimeout(() => { this.initial = true; }, 1000);
Do you have any sample for "chart.initChart()".
https://www.primefaces.org/primeng/#/chartFor me it works without a timeout, I had the problem only if I didnt initalize the graph with some random data. And this way is much easier, than redrwaing the whole div everytime. You can set the timeout on just 0.1 seconds, and it should work just fine as well.Methods
Name Parameters Description
refresh - Redraws the graph with new data.
reinit - Destroys the graph first and then creates it again.
that is how I initiliaze my graphs for now.Code: Select all
ngOnInit() { this.ProfileService.getProfiles().then(profiles => this.profiles = profiles) .then(() => { this.update_bar_charts(); this.update_dognutcharts(); this.chart.refresh(); this.chart2.refresh(); }); }
Just Try this: create a button and on click call a function; inside it change the data and den do chart.refresh(). Tell me if this works for you! coz this is not working for me.
Saurav Dubey wrote: ↑28 Mar 2017, 10:50
I have read the documentation. Using inside ngOnInit u dont need chart.refresh(). your chart is displayed just by initialising the data.
Just Try this: create a button and on click call a function; inside it change the data and den do chart.refresh(). Tell me if this works for you! coz this is not working for me.
Well, I get the data from a service, thats why I personally need to load it into all my charts, otherwise they are empty at the beginning.
I worked with a button before, because I couldnt figure out how to load initial data without hardcoding it and it worked perfectly fine with a timeout!
if I call update(chart) on a button click, it works perfectly fine with timeout. I dont understand, why you have a problem with it...
Code: Select all
update(chart: UIChart) {
this.update_bar_chart();
setTimeout(function () { chart.refresh() }, 500);
}
update_bar_charts() {
for (var i = 0; i < Object.keys(this.profiles).length; i++){
this.data3[i] = this.profiles[i].hours;
}
this.data0.datasets[0].data = this.data3;
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 31 guests