score:9
you are creating a new chart, that's why you end up with the old chart behind the new one.
one simple option that i've used: remove the old chart from the canvas that you are using for the chart:
$('#canvas').replacewith('<canvas id="canvas"></canvas>');
and now create the chart with the new data in the same canvas
var ctxchart = document.getelementbyid("canvas").getcontext("2d");
window.mychart = new chart(ctxchart).line(newdata, options);
hope it helps!
score:1
for those of you wondering the same thing with pie charts, doesn't look like there's a given public method that works but you can use an easy workaround by removing the data yourself:
var piechart = new chart(ctx).doughnut(undefined, piechartoptions);
piechart.segments.splice(0, piechart.segments.length);
seems to work ok, wish they would just add a remove all method or make the clear actually work.
Source: stackoverflow.com
Related Query
- Chart JS Replace All Dataset Data
- Add all data in the tooltip of Chart JS
- Chart.js replace all data
- Chart JS not showing all data
- ChartJS: chart not show all data
- How to show tooltip value of all data falling on the same axis in chart js?
- chart js: when all the values passed to data are zeros, nothing is showing
- Show/hide All nested data in ChartJS Pie chart when outer is shown/hidden
- How do I destroy/update Chart Data in this chart.js code example?
- Reproduce Error in Chartjs v2 Polar chart not plotting all supplied data
- getting additional value fields from data source for dx.chartjs doughnut chart
- Not all date data shows on x axis line chart
- Chart JS: Donut/Doughnut Chart: Tooltip to be shown always for all the data. All tooltip is not shown when multiple data are with 0 data
- chart.js - Pie Chart doesn't display all data
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- Chartjs Bar Chart showing old data when hovering
- Chartjs random colors for each part of pie chart with data dynamically from database
- Chart.js - Hover labels to display data for all data points on x-axis
- ChartJS - Draw chart with label by month, data by day
- line chart with {x, y} point data displays only 2 values
- Chart JS data labels getting cut
- chart js tooltip how to control the data that show
- Chart.js Timeseries chart - formatting and missing data values
- Chart JS show multiple data points for the same label
- How to display data labels outside in pie chart with lines in ionic
- ng2-charts customize data and whole html content of tooltip displayed when hovering on bar chart
- Show data dynamically in line chart - ChartJS
- Chartjs - data format for bar chart with multi-level x-axes
- ChartJS: Draw vertical line at data point on chart on mouseover
- Chartjs - show elements in all datasets on hover using bar chart
More Query from same tag
- How to print a chart rendered by code
- ChartJs multiaxis chart show different label bottom and top
- How do you use user input as data values in chart.js?
- angular-charts.js doesnt work with ionic
- How to create a chart with chartjs.org with data from an array?
- ReactChart2 - Line is not a registered Element
- how to customize tool tip while mouse go over bars on Chart js bar chart
- Chart JS - Horizontal Bar Chart Not Filling Canvas
- Create a heatmap/punchcard Using Chart.js
- Chart.js zeros handling
- ChartJS - x axis labels orientation
- How to get Uptime charts for Web Monitoring like Dynatrace?
- How to make Radar chart's tooltips show "labels" in vue-chartjs?
- Making chartjs scrollable on the x-axis
- Using Different Colors In a Chart
- Can't resolve 'chart.js/auto'
- How to loop over Chart.js with Django list view
- chart.js plugins.register function with outer data
- Chart.js pie tooltip getting cut
- how to label the x and y axis - in a line graph
- json file to charts
- How to make label always visible on DoughnutChart.js
- Highlight background on a single hour with chart.js and annotations
- Hiding spaces with zero values in bar chart with chart.js
- Chart bundle js is not showing dynamic data
- getElementById on element from parent component returns null, when called in ngAfterViewInit() of child component
- ng2-charts : Newly added rows not getting displayed on phone devices
- How to set start value as “0” in Chart.js Laravel
- Angular js install external library failed to instantiate module npm
- ChartJS: how to change data in hover box?