score:1
When using ng2-charts
, there's no need to invoke chart.update()
, let Angular change detection do its job. In case it doesn't work as expected, reassign the data
array after pushing a new value to it. This can be done using Array.slice()
as shown below.
this.yrSubscription = this.userDataStore.pipe(select(selectYrReport))
.subscribe(el => {
el.sessions.forEach(item => {
this.datasetsSessions[0].data.push(+item);
this.datasetsSessions[0].data = this.datasetsSessions[0].data.slice();
});
});
But the main issue is probably located in the _registerCustomChartJSPlugin
method. Instead of defining such a method, define its content in a chartPlugins
variable as follows:
chartPlugins = [{
afterDatasetsDraw: (chart, easing): any => {
...
}
}];
Inside the HTML template, you then have to provide chartPlugins
as follows.
<canvas baseChart
[datasets]="datasetsSessions"
[plugins]="chartPlugins"
...
</canvas>
Please have a look at this StackBlitz.
score:-3
Above Component Decorator have this :-
var require: any;
var Chart = require('chart.js');
In component have a property for keeping instance of chart
public chart: Chart;
First you need to understand is that Chart.plugins.register will only register a plugin globally for all charts. https://www.chartjs.org/docs/latest/developers/plugins.html#global-plugins
You need a chart for this plugin to apply
Lets Say you have a Canvas in your HTML like :-
<div>
<canvas id="canvas">{{ chart }}</canvas>
</div>
You need to update your inside ngoninit to ngrx Subscription To create a new chart if its not available.
ngOnInit() {
this._registerCustomChartJSPlugin();
this.yrSubscription = this.userDataStore.pipe(select(selectYrReport))
.subscribe(el => {
if(!this.chart) {
this.createChart();
}
el.sessions.forEach(item => {
this.datasetsSessions[0].data.push(+item);
});
this.chart.update();
});
}
public createChart() {
this.chart = new Chart('canvas'); //Include if any object required as second Parameter
}
score:0
Assuming that you are registering the charts in the same component . First of all you need to keep a reference to your custom chart. In your component add this in your component class
customChartInstance : Chart;
Then in your afterDatasetsDraw
add
this.customChartInstance=chart
then in your subscription add
this.chart.update();
Source: stackoverflow.com
Related Query
- Update charts in chartjs and angular
- zoom and pan on charts in angular
- Create a rounded bar graph with Angular and chartJS
- Make y-axis sticky when having horizontal scroll on chartJS and Angular
- Setting Common labels and background color common for all the charts in ChartJs
- How to update a chart using VueJS and ChartJS
- Change font size and font color in Chartjs Angular 5
- Order and hide items of legend by value with Chartjs Angular
- how to increase space between legend and chart in chartjs (ng2charts ) using angular
- Creating charts dynamically using ChartJS and AngularJS
- Angular 9 chartJs is not updating view after data update
- How to toggle between Custom tooltip and normal tooltip in chartjs and angular
- Angular 6 ChartJS create canvas dynamically and create graph on it - an example?
- How to add left padding for my charts done in ChartJs and my Google Map so it is not glued to the limit of the page on the left
- Flickering of charts and getcontext error with chartjs in the context of Vuejs
- Angular 6: chartjs value not updating with dynamic value update
- Angular and ChartJS to create bar chart
- How to 1. pass two datasets and 2.have permanent label on charts in Chartjs
- Is there a better way to create an 'n' number of charts in ChartJS and ASP.NET C#?
- My Chartjs is not updating after setstate full code attached Reactjs Update
- How can I update my ChartJS in real time (It's works only when I zoom-in and zoom-out)
- chartjs angular update order
- The dataset for bar graph is not set properly using ng2 charts and ng5-slider in Angular
- How to create rounded bar graph with Angular 7 and Chartjs (v2)
- How to extend chartjs line charts in ReactJS to show solid and dashed line together?
- Page break in Angular with Chartjs and tables
- Angular ChartJs does not show Data for multiple Charts
- Angular 8 and ng2 charts - Updating labels and data
- ChartJS separate charts per JSON object, and not when hovered over
- Chartjs charts drawing with the same colour after update
More Query from same tag
- How to make a prefilled doughnut in chart.js?
- chartjs + Angular6 is not showing charts or any error
- Moving vertical line when hovering over the chart using chart.js in v2.9.4
- What is the correct format for time data in chartjs?
- Border behind grid line
- Fill Chart.js bar chart with diagonal stripes or other patterns
- ChartJS plotting x/y in a line chart
- add info for points in line chart (js)
- Chart.js How to get min-max values of X axis?
- ChartJS - change chart type by changing y-axis Label
- how to add FAHRENHEIT symbol in chart js donut chart
- How to plot object to charts.js
- Chart.js Y axis label, reverse tooltip order, shorten X axis labels
- Making my website interactive with the size of the screen/browser
- Chart.js bar chart : Grid color and hide label
- Angular 2: How to pass my API data to graph and Display the Graph with data
- chart.js first bar is not showing
- copy object in Chart.js
- How scale sector in doughnut chartjs on hover?
- Type check for getElementById only works with optional chaining, not with type check
- Chart.js show data in chronological order
- Using unknown number of datasets in Chart.js
- Chart.js creating a line graph using dates
- Styling problems with Chart.Js
- Chart.js not appearing in tabs
- How to set vue3-chartjs fixed height?
- Add \n or line break on chart.js (pie chart) labels
- PrimeNG pie chart randomly displays, and displays on change of resolution
- Chartjs bar chart trying to get labels from datasets
- How to make animated bar graph with canvas?