使用 chart.js 将数据添加到折线图 [英] Add data to line chart using chart.js

查看:26
本文介绍了使用 chart.js 将数据添加到折线图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在图表中添加一个新数据,但浏览器在调用我的添加"函数时抛出一个错误,提示未捕获的类型错误:未定义不是函数".

I would like to add a new data in chart but the browser throws an error that says "Uncaught TypeError: undefined is not a function" when calling to my "Add" function.

图表对象似乎无法识别AddData"功能,但我不知道如何解决.在文档中显示此功能对我来说无法正常工作.

It seems that the chart object does not recognized the "AddData" function but I don't know how to solve it. In documentation appears this function it doesn't work properly to me.

.addData(valuesArray, 标签)在 Chart 实例上调用 addData(valuesArray, label) 为每个数据集传递一个值数组,以及这些点的标签.

.addData( valuesArray, label ) Calling addData(valuesArray, label) on your Chart instance passing an array of values for each dataset, along with a label for those points.

小提琴样本http://jsfiddle.net/rferreiraperez/pevy7vsz/5/

var myLineChart = new Chart(ctx).Line(data);

$("#add").on( "click", function() {
    var month = $("#month").val();
    var point = $("#point").val();
    var points = new Array();
    points.push(point);
    console.log("adding...");
    console.log("month:" + month);
    console.log("point:" + point);
    myLineChart.addData(points, month);
});

非常感谢.

推荐答案

我测试过了!发现你使用的Chart.js版本是0.2.0,但是没有addData方法.

I tested it! And found that the version of the Chart.js you were used is 0.2.0, but it doesn't has the addData method.

您应该使用最新版本,然后再试一次,它应该可以工作!

You should use the latest version, and try again, it should work!

http://www.chartjs.org/assets/Chart.min.js

这篇关于使用 chart.js 将数据添加到折线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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