隐藏Chart.js中的提示框颜色框不起作用。

huangapple go评论65阅读模式
英文:

Hiding tooltip color box in Chart.js not working

问题

根据Chart.js文档,要从工具提示中移除颜色框,只需将displayColors: false添加到tooltip,这也是类似问题的已接受答案,链接在这里https://stackoverflow.com/questions/43793622/how-to-remove-square-label-from-tooltip-and-make-its-information-in-one-line
但它在我的代码中不起作用。这里是编辑器的链接https://stackblitz.com/edit/stackblitz-starters-ntdk3g?file=src%2FApp.js

英文:

As per Chart.js docs, all that's needed to remove the color box from tooltips is to add displayColors: false to tooltip, that's also the accepted answer to a similar question here https://stackoverflow.com/questions/43793622/how-to-remove-square-label-from-tooltip-and-make-its-information-in-one-line
But it doesn't work in my code. Here's the link to the editor https://stackblitz.com/edit/stackblitz-starters-ntdk3g?file=src%2FApp.js

答案1

得分: 1

您的<LineChart chartData={activityData} options={{ plugins: { tooltip: { displayColors: false } } }}/>正常工作,如果您在LineChart.js中启用`options`参数([stackblitz fork](https://stackblitz.com/edit/stackblitz-starters-nxq73c?file=src%2FApp.js,src%2FLineChart.js))

但是,尝试将`options`设置在与`labels`和`datasets`相同的级别将不起作用,因为`labels`和`datasets`是`data`的键,而`options`不应该是`data`的一部分,而应该与`data`在同一级别;在react-charts2中,这意味着`options`应该是`Line`(或其他)组件的单独参数,参见此[文档链接](https://react-chartjs-2.js.org/components/line)。
英文:

Your

<LineChart chartData={activityData} options={{ 
    plugins: {
      tooltip: {
        displayColors: false // tried this also
      }
    }
}}/>

is working OK, if you enable the options argument in LineChart.js (stackblitz fork)

However, the attempt to set options at the same level as labels and datasets will not work, since labels and datasets are keys of data, and options should not be part of data, but at the same level as data; in react-charts2 this means options should be a separate argument to the Line (or other) component, see this doc link.

huangapple
  • 本文由 发表于 2023年6月9日 06:49:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76436166.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定