【问题标题】:react-chartjs-2 hiding axis labelreact-chartjs-2 隐藏轴标签
【发布时间】:2022-11-02 21:43:52
【问题描述】:

我正在尝试隐藏 yAxis 标签。我尝试了display: false 属性,但没有奏效。 我的代码如下:

export const options = {
  responsive: true,
  interaction: { includeInvisible: true, intersect: false },
  tooltip: {
    backgroundColor: "rgba(0, 0, 0, 0.3)",
    displayColors: false,
    multiKeyBackground: "rgba(0, 0, 0, 0)",
  },
  scale: {
    y1: {
      min: 0,
      ticks: {
        count: 5,
      },
      grid: { borderDash: [3], color: "rgb(126,126,126)", tickLength: 0 },
    },
    y2: {
      display: false,
      position: "right",
      max: Math.max(...BTCPrices.map((el) => el.Volume)) * 10,
      ticks: {
        count: 5,
      },
    },
    x: {
      ticks: {},
    },
  },
  plugins: {
    legend: {
      display: false,
    },
  },
};

这是描述问题的图像: 感谢您的帮助!

【问题讨论】:

    标签: reactjs charts chart.js react-chartjs-2


    【解决方案1】:

    这是因为你的配置没有被选中,你把你的规模配置放在options.scale 命名空间白色它需要在options.scales 中配置所以你需要在最后添加一个额外的s

    【讨论】:

    • 这就是我喜欢打字稿的原因。如果你使用它,你永远不会犯这样的错误。
    【解决方案2】:

    这就是我设法摆脱标签的方式,我认为在你的情况下,而不是将会是y2

      y: {
          ticks: {
            display: false, //this will remove only the label
          },
        },
    

    【讨论】:

      猜你喜欢
      • 2015-12-26
      • 1970-01-01
      • 1970-01-01
      • 2011-05-04
      • 1970-01-01
      • 2022-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多