百分比轴仅在正范围内

问题描述 投票:0回答:1

如何将百分比刻度限制在第一个 Y 轴的正范围内?划掉的曲线只能显示在如图所示的正区域。

我当前的 Y 轴配置:

   y: {
        type: 'linear', 
        position: 'left',
        stacked: true,
        ticks: {
           stepSize: 1000,
           font: {
             size: 20,
           }
        }
      },
    
      y2: {
        type: 'linear',
        position: 'right',
        min: 0,
        max: 100,
        grid: {
            drawOnChartArea: false
        },
        ticks: {
           stepSize: 20,
           font: {
             size: 20,
           },
           callback: function(value, index, values) {
              return value + ` %`;
           }
        }
      },

    }
chart.js axis percentage
1个回答
0
投票

解决方案如下:

y2: {
        type: 'linear',
        display: 'auto',
        position: 'right',
        min: -100,
        max: 100,
        grid: {
            drawOnChartArea: false
        },
        ticks: {
           stepSize: 20,
           font: {
             size: 20,
           },
           callback: function(value, index, values) {
              return value >= 0 ? value + ' %' : '';
           }
        }
      },

© www.soinside.com 2019 - 2024. All rights reserved.