Chart.js工具提示函数

yebdmbv4  于 2022-11-06  发布在  Chart.js
关注(0)|答案(1)|浏览(271)

我想我的工具提示自定义没有生效,因为整个工具提示功能没有运行。所以,我尝试console.log一个数字,如果我将鼠标悬停在图表上,数字是否不会被记录?

  1. let myChart= document.getElementById('myChart').getContext('2d');
  2. let theChart= new Chart(myChart, {
  3. type: 'doughnut',
  4. data: {
  5. labels: ['January', 'February', 'March'],
  6. datasets: [{
  7. label: 'Temperature',
  8. data: [12, 19, 3],
  9. backgroundColor: ['rgba(255, 99, 132, 0.2)', "rgba(132, 99, 255, 0.2)", "rgba(255, 132, 99, 0.2)"],
  10. borderColor: 'rgba(255, 99, 132, 1)',
  11. borderWidth: 1
  12. }]
  13. },
  14. options: {
  15. plugins: {
  16. tooltip: {
  17. callbacks: {
  18. label: function (tooltipItem, data) {
  19. var label = myChart.data.labels[1.0];
  20. console.log("2");
  21. return 0;
  22. }
  23. }
  24. }
  25. }
  26. }
  27. });
  28. </script>```
gcxthw6b

gcxthw6b1#

由于它不工作,我假设您使用的是chart.js的V2,在这种情况下,您必须在options.tooltips名称空间而不是options.plugins.tooltip中配置工具提示选项

相关问题