我想在条形图上将numberValue的值显示为悬停时的标签.我try 了许多方法,但在栏上悬停时没有显示任何内容.以下是代码:

getBarChart() {
    this.http.get(API).subscribe({
      next: (data) => {
        this.totalAmount= data;
        let splitted = this.totalAmount.toString().split(",");
        let numberValue= splitted[0];
        let totalAmountPerMonth = splitted[1];
        let month = splitted[2];

        this.barChart.data.labels = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

        let dataValues = new Array(12).fill(null);
        let monthIndex = parseInt(month) - 1;
        dataValues[monthIndex] = totalAmountPerMonth;

        this.barChart.data.datasets = [
          {
            label: "Total Amount",
            data: dataValues,
            backgroundColor: DARK_BLUE
          }
        ];
        this.barChart.update();
      },
      error: (err) => {
        console.log(err);
      }
    });

    Chart.register(BarController);
    Chart.register(CategoryScale);
    Chart.register(LinearScale);
    Chart.register(BarElement);

    this.barChart = new Chart("barChart", {
      type: 'bar',
      data: {
        labels: [],
        datasets: []
      },
      options: {
        aspectRatio: 2.5,
        scales: {
          x: {
            title: {
              display: true,
              text: "Month"
            }
          },
          y: {
            title: {
              display: true,
              text: "Total Amount"
            }
          }
        },
        plugins: {
          legend: {
            display: false
          },
          tooltip: {
            callbacks: {
              label: (context) => {
                const value = context.dataset.data[context.dataIndex];
                const numberValue = value !== null ? value : 'N/A';
                return `Number: ${numberValue}`;
              }
            }
          }
        },
      }
    });
  }

推荐答案

您需要导入并注册Tooltip才能显示它

Typescript相关问答推荐

React组件数组及其props 的类型定义

使用FormArray在Angular中添加排序

TypScript在对象上强制执行值类型时推断对象文字类型?

当类型断言函数返回假时,TypScript正在推断从不类型

需要使用相同组件重新加载路由变更数据—React TSX

使用React处理Websocket数据

错误TS2403:后续变量声明必须具有相同的类型.变量';CRYPTO';的类型必须是';CRYPATO';,但这里的类型是';CRYPATO';

下载量怎么会超过下载量?

如何获取受类型脚本泛型约束的有效输入参数

复选框Angular 在Ngfor中的其他块中重复

自定义 Select 组件的类型问题:使用带逗号的泛型类型<;T与不带逗号的<;T&>;时出错

如何将类似数组的对象(字符串::匹配结果)转换为类型脚本中的数组?

声明遵循映射类型的接口

在构建Angular 应用程序时,有没有办法通过CLI传递参数?

作为参数的KeyOf变量的类型

我如何键入它,以便具有字符串或数字构造函数的数组可以作为字符串或数字键入s或n

如何为对象数组中的每个条目推断不同的泛型

类型分布在第一个泛型上,但不分布在第二个泛型上

传入类型参数<;T>;变容函数

对象可能未定义(通用)