Chart.js左右Y轴相同

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

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

  1. yAxes: [{
  2. position: 'right'
  3. }]

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

qlckcl4x

qlckcl4x1#

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

  1. scales: {
  2. yAxes: [{
  3. display: true,
  4. position: 'right',
  5. ticks: {
  6. beginAtZero: true
  7. }
  8. }, {
  9. display: true,
  10. position: 'left',
  11. ticks: {
  12. beginAtZero: true,
  13. max: 45,
  14. min: 0,
  15. stepSize: 5
  16. }
  17. }]
  18. }

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

展开查看全部
fumotvh3

fumotvh32#

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

  1. scales: {
  2. yAxes: [{
  3. display: true,
  4. position: 'right',
  5. ticks: {
  6. beginAtZero: false,
  7. max: 2000,
  8. min: 1000,
  9. stepSize: 100
  10. }
  11. }, {
  12. display: true,
  13. position: 'left',
  14. ticks: {
  15. beginAtZero: false,
  16. max: 2000,
  17. min: 1000,
  18. stepSize: 100
  19. }
  20. }]
  21. }

字符串

展开查看全部
dldeef67

dldeef673#

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

  1. scales: {
  2. myScale: {
  3. type: 'linear',
  4. position: 'right',
  5. }
  6. }

字符串

相关问题