【问题标题】:Truncating canvas label in ChartJS v3.5.1ChartJS v3.5.1 中截断画布标签
【发布时间】:2021-10-21 04:38:28
【问题描述】:

我有一个带有很长标签的条形图,它正在缩小画布。如果标签超过 10 个字符,我会尝试截断它。我尝试了在另一篇文章中找到的解决方案:

options: {
        responsive: true,
        maintainAspectRatio: false,
        scales: {
            xAxes: [{
                ticks: {
                    callback: function (value: string) {
                        return value.substr(0, 10);//truncate
                    },
                }
            }],
            yAxes: [{}]
        },
        tooltips: {
            enabled: true,
            mode: 'label',
        },
    }

这似乎不起作用,无法弄清楚原因。

bar char image here

【问题讨论】:

    标签: reactjs typescript react-chartjs


    【解决方案1】:

    在这里,您只需删除对我有用的函数中的字符串

    options: {
      responsive: true,
      maintainAspectRatio: false,
      scales: {
          xAxes: [{
              ticks: {
                  callback: function (value) {
                      return value.substr(0, 10);//truncate
                  },
              }
          }],
          yAxes: [{}]
      },
      tooltips: {
          enabled: true,
          mode: 'label',
      },
    }
    

    【讨论】:

      猜你喜欢
      • 2017-12-15
      • 2012-03-12
      • 2018-04-20
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      相关资源
      最近更新 更多