Chart.js replace all data(Chart.js 替换所有数据)
问题描述
我遇到了 Chart.js 的问题.
im having a issue with Chart.js.
首先,我设置了一个数据,然后当一个参数发生变化时,我想重新绑定整个图表.这项工作,但它就像旧数据仍然落后于新数据的图表.
Firts, I set a data, and then when a parameter change, I want rebind the entire chart. This work, but its like the chart with the old data still behind the new one.
第一 ->
chart.Line(data, options);
在一个事件中->
chart.Line(newdata, options);
我看到了这个解决方案chart.js 加载全新数据
但我不喜欢这种方式.我在角度指令上下文中,所以这不是最好的方法.
but I dont like this way. Im in a angular directive context, so it's not the best aproach.
我试过没有结果
.update()、.removeData()、.clear()、.destroy() 等
.update( ), .removeData( ), .clear(), .destroy(), etc
这是我当前的指令
http://plnkr.co/edit/qn2UUyznonKm6zgEi8FW?p=catalogue
有什么想法吗?
推荐答案
您正在创建一个新图表,这就是为什么您最终会在新图表后面使用旧图表.
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);
希望对你有帮助!
这篇关于Chart.js 替换所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Chart.js 替换所有数据


- addEventListener 在 IE 11 中不起作用 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 400或500级别的HTTP响应 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01