Jquery – Add data to line chart using chart.js

chart.jschartsjquery

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.

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, label )
Calling addData(valuesArray, label) on your Chart instance passing an array of values for each dataset, along with a label for those points.

Fiddle sample
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);
});

Thanks a lot.

Best Answer

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