Chartjs-Mulitple canvas-images (by Chart.js) with toDataURL()

0👍

You can have different callbacks with different names. “done” is just an example name (a better name would probably be “completed”).

For example – first create two option objects, one for each chart:

var options1 = { 
    onAnimationComplete: done1
};

var options2 = { 
    onAnimationComplete: done2
};

Then initialize the charts with those:

...
var Chart1  = new Chart(ct1).Line(lineChartData1, options1);

...
var Chart2  = new Chart(ct2).Line(lineChartData2, options2);

And finally define the callbacks:

function done1() {
    var url = document.getElementById("image1").toDataURL();
    document.getElementById("canvas_link_1").href = url;
}

function done2() {
    var url = document.getElementById("image2").toDataURL();
    document.getElementById("canvas_link_2").href = url;
}

Hope this helps (and that I understood the problem correctly) !

Leave a comment