score:2

Accepted answer

i'm using v2.0.0 from the dev branch (the file header reads 2.0.0-alpha, and the file i'm looking at is https://github.com/nnnick/chart.js/blob/f3eb6f4a433b4f34a582842dcf7b42f710861a7d/chart.js)

you need to make a few changes to get your fiddle to work


make the chart type an option

i think v2.0 has only one constructor for all chart types. so

chartdata = new chart(ctx).line({

should be

chartdata = new chart(ctx, {
    type: "line",

add a type for the 2nd y-axis

scaletype: "linear"

to

type: "linear",

type is the property name. it doesn't cause any problem for the first y axis since it's optional there (your scaletype: "linear" on the first instance doesn't actually do anything and you can drop it)


remove the window.onload

your fiddle is already set to execute onload


change the method signature

as far as i could see from the code, the method signature has changed for adddata. it is now as follows (from the code) - note that this could change anytime

// add data to the given dataset
// @param data: the data to add
// @param {number} datasetindex : the index of the dataset to add to
// @param {number} index : the index of the data
adddata: function adddata(data, datasetindex, index)

so a better version of your setinterval would be

setinterval(function () {
    var latestlabel = chartlabel[6];

    chartdata.adddata(12, 0, latestlabel);
    chartdata.adddata(5, 1, latestlabel);
    chartdata.removedata(0, 0);
    chartdata.removedata(1, 0);

}, 7000);

https://jsfiddle.net/bsgc9tu7/


Related Query

More Query from same tag