How to add second Y-axis for Bar and Line chart in Chart.js?

前端 未结 1 875
独厮守ぢ
独厮守ぢ 2021-02-15 13:45

I am trying to add a double Y-axis in Chart.js for two dataset comparisons. I\'m currently using Leigh Quince\'s LineBar extension which was the answer found here: Chart.js how

相关标签:
1条回答
  • 2021-02-15 14:17

    To show a Line Chart with two Y axis, @khertan made a pull request to add this feature >> https://github.com/nnnick/Chart.js/pull/1355

    You can grab the modified Chart.js file here >> https://github.com/khertan/Chart.js/tree/9edcc71f97361bb45c8fe93d07acb1917c2b4807

    You'll only need to add the option to your options variable:

    var options = {
        ...
        scaleUse2Y: true,
        ...
    };
    

    And then instantiate a normal Line chart:

    var chart = new Chart(ctx).Line(data, options);
    

    Problem is that if you're using an extension like StackedBar, for example, it will probably break... That must be the reason why it hasn't been merged with master's branch of Chart.js yet. Patience for the 2.0 version release.

    0 讨论(0)
提交回复
热议问题