chart.js之替换所有数据 [英] Chart.js replace all data

查看:745
本文介绍了chart.js之替换所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有chart.js之一个问题IM。

im having a issue with Chart.js.

Firts,我设置一个数据,然后当一个参数变化,我想重新绑定整个图表。
这项工作,但它像旧的数据图表仍落后于新的。

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);

在一个活动 - >

in a event ->

  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="canvasBarras"></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之替换所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆