score:6
There appears to be an issue with the Charts library modifying the existing object on the root scope, and thereby ignoring it forever afterward. I can't really trace down what is doing it, but here's a fix for you: http://plnkr.co/edit/jDQFV62FSeXAQJ6o7jE8
Here is what you had
scope.$watch('config', function(newVal) {
if(angular.isDefined(newVal)) {
if(charts) {
charts.destroy();
}
var ctx = element[0].getContext("2d");
charts = new Chart(ctx, scope.config);
//scope.$emit('create', charts);
}
});
Above, you can see that you're passing scope.config
directly into the charts method. That appears to be modifying the data somehow, and since that's passed by reference, you're actually modifying $rootScope.sales.charts
. If you copy that object and use it locally like below, you don't have that problem.
Here's how I fixed it.
scope.$watch('config', function(newVal) {
var config = angular.copy(scope.config);
if(angular.isDefined(newVal)) {
if(charts) {
charts.destroy();
}
var ctx = element[0].getContext("2d");
charts = new Chart(ctx, config);
//scope.$emit('create', charts);
}
});
You can see that instead of passing that object directly in, we use angular to make a copy (angular.copy()
), and that's the object we pass in.
score:2
I think it has relation with the id of the canvas where you are drawing. I've had this problem too amd it was because i was using the same id for the canvas of two graphs in different views. Be sure that those ids are different and that the javasrcipt of each graph is in the controller of each view or in each view itself.
Taking a look at your pluker I see that you are using the same html for the graph and I guess that when angular moves from one of your views to the other thinks that the graph is already drawn. Differentiating two graphs will solve the problem. I don't know of there is any other approach that allows using the same html for the canvas of the graph.
Hope it helps you solve it
Source: stackoverflow.com
Related Query
- Angularjs - Charts.js: Same chart element doesn't redraw on other view
- Destroy chart.js bar graph to redraw other graph in same <canvas>
- Chart.elements.Rectangle.prototype.draw inpacting on other charts in the same page(Angular)
- how to not repeat code while creating multiple charts in chart js
- Chart Js Change Label orientation on x-Axis for Line Charts
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- How to save Chart JS charts as image without black background using blobs and filesaver?
- How to Draw Gantt chart using chart js or other libraries
- Chart.js bar chart is overflowing its containing element
- Chart JS show multiple data points for the same label
- Fill Chart.js bar chart with diagonal stripes or other patterns
- Chart.js - Multiple Doughnut Charts on same Canvas
- chart.js - link to other page when click on specific section in chart
- Mouse over on line chart data active other data-set in Chart.js
- Multiple charts on same page not working - ng2-charts
- Display Date Label in axes - chart js/ng2 charts
- How to make bar chart animation where all bars grow at the same speed?
- chart js data-point between bar charts
- How to add ChartJS code in Html2Pdf to view image
- ChartJS - how to display line chart with single element as a line? (not as a dot)
- Multiple Chart.js Charts in Partial Views Overwriting Each Other
- Redraw Chart.js Chart with Json_encoded array from ajax request
- Vue Chart 3 - Doughnut Charts with Text in the Middle (Trouble registering a plugin)
- A chart Js error issue are occured in my Laravel other page?
- Cannot create chart on react element
- How can I load multiple Chartjs charts with different data on the same page?
- Chart JS Crosshair - Linked Charts without linked Legends
- Chart.js creating multiple Charts in Angular in same Component
- Multiple charts rendering on top of each other
- Passing an Array from a Flask view to the javascript code of another view
More Query from same tag
- How to write better code in es6 for formatting an object with array values
- Click event on stacked bar chart - ChartJs
- ChartJS not showing data for time series bar chart
- Chartjs unexpected visual animation effect when adding data
- custom ticks in ChartsJS line plot
- Skip decimal points on y-axis in chartJS
- How to set specific height for chartJs background color in terms of yAxis value
- Chart JS prepend labels to x-axis with addData
- Chart.js not deploying properly on Heroku
- How to show Charts.js lables
- Destroying Chart js within useEffect - React
- What is self.scale.endPoint chartJs v2.0?
- Datas put one on each other on chart.js
- Change label color on pie-chart of ng2-charts/charts.js
- Why my ng2-chart data isn't scaled properly?
- how to display chart data as html table chartjs
- Problem to create dynamic pie chart in ChartJS
- Horizontal scroll in vue-chartjs
- How do I get a chart.js chart to display data in a Node/React web application?
- Chart.js 2.x animation onComplete not responding
- how to hide 0 value on Yaxis in Chart.js with negative values
- Draw y-axis inside the graph area with chart js
- Css style not working well when resizing chart height in angular application
- Set labels from array
- time series stream, removing am/pm on x axis and 24 hour format
- Angular-Chart.js chart doesn't shown, if data added automatically
- chartjs plugin datalabels does not show value on charts
- using data structures in chartjs
- Setting Common labels and background color common for all the charts in ChartJs
- How to remove automatically applied background color to the body?