Chart.js左右Y轴相同

sdnqo3pr  于 2023-08-05  发布在  Chart.js
关注(0)|答案(3)|浏览(152)

我有一个使用chart.js制作的工作图表,默认情况下Y轴在左侧,但我希望Y轴数据在两侧
我知道我可以改变边使用:

yAxes: [{
 position: 'right'
}]

字符串
但我希望两边的Y轴数据相同。知道怎么做吗
谢谢你的帮助。

qlckcl4x

qlckcl4x1#

这里有一个方法:
你的yAxes是一个Array**[],里面有对象{}**,所以你需要给它添加另一个yScale,这里是一个例子:

scales: {
   yAxes: [{
    display: true,
    position: 'right',
    ticks: {
     beginAtZero: true
    }
   }, {
    display: true,
    position: 'left',
    ticks: {
     beginAtZero: true,
     max: 45,
     min: 0,
     stepSize: 5
    }
   }]
 }

字符串
x1c 0d1x的数据
Live demo: Chart.js Double yAxis
请注意,您必须重新格式化其中一个新轴以符合默认值,您可能需要格式化两个参数或将这些参数绑定到您的数据,如果它将根据您想要的外观进行更改。

fumotvh3

fumotvh32#

@Keno的解决方案对我不起作用。因为我的图表需要是min: 1000而不是min: 0
对我有用的是:

scales: {
   yAxes: [{
    display: true,
    position: 'right',
    ticks: {
     beginAtZero: false,
     max: 2000,
     min: 1000,
     stepSize: 100
    }
   }, {
    display: true,
    position: 'left',
    ticks: {
     beginAtZero: false,
     max: 2000,
     min: 1000,
     stepSize: 100
    }
   }]
 }

字符串

dldeef67

dldeef673#

这是我的工作,但我仍然需要显示没有在左侧的比例

scales: {
    myScale: {
        type: 'linear',
        position: 'right',
    }
}

字符串

相关问题