Chartjs-Is it possible to dynamically add more Y Axes or more X Axes on chart js?

1👍

you can destroy the chart and run new Chart function again.

Here is fiddle : https://jsfiddle.net/cbalakus/fhadc9by/

function addYAxis() {
    var leng = window.myLine.options.scales.yAxes.length + 1;
    var clr = chartColors[Math.floor(Math.random() * chartColors.length)];
    opts.scales.yAxes.push({
        type: "linear",
        display: true,
        position: "right",
        id: "y-axis-" + leng,
        ticks: {
            fontColor: clr
        }
    });
        lineChartData.datasets.push({
        label: "y-axis-" + leng,
        borderColor: clr,
        backgroundColor: clr,
        fill: false,
        data: getDatas(),
        yAxisID: "y-axis-" + leng,

    });
    window.myLine.destroy();
    var ctx = document.getElementById("cvs").getContext("2d");
    window.myLine = Chart.Line(ctx, {
        data: lineChartData,
        options: opts
    });
}

Leave a comment