如何更改chartjs数据文本

r9f1avp5  于 2022-11-07  发布在  Chart.js
关注(0)|答案(1)|浏览(182)

你能帮我做我在图像中的项目吗?
我需要做的是将图表中的数据文本与图像中的数据文本一个在另一个下面。

下面是我在codepen中的代码:https://codepen.io/korayhan-aslan/pen/RwQvVbV

  1. enter code here
bbuxkriu

bbuxkriu1#

要实现这一点,请将generateLabels函数中“text”的值从字符串更改为数组,并添加工具提示插件。
在generateLabels函数中修改文本

  1. return {
  2. text: [typerOne,typerTwo], # before typerTwo + ": " + typerOne
  3. fillStyle: style.backgroundColor,
  4. strokeStyle: style.borderColor,
  5. lineWidth: style.borderWidth,
  6. pointStyle: pointStyle,
  7. hidden: !chart.getDataVisibility(i),
  8. // Extra data used for toggling the correct item
  9. index: i
  10. };

修改工具提示标签

  1. tooltip: {
  2. callbacks: {
  3. label: function(context) {
  4. return [context.formattedValue, context.label]
  5. }
  6. }
  7. },

第一个

展开查看全部

相关问题