0

我想在 y 轴上显示带有特定货币符号的数据,如工具提示中的突出显示区域。我已经自定义了工具提示,但提供给图形的动态数据不受我控制。在此处输入图像描述

这是我尝试过的代码

<Line
ref="chart"
data={ {
labels: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
datasets: [
{
     label: "",
     fill: false,
     lineTension: 0,
     backgroundColor: "rgba(75,192,192,0.4)",
     borderColor: "#71C898",
     borderCapStyle: "butt",
     borderDash: [],
     borderDashOffset: 0.0,
     borderJoinStyle: "miter",
     pointBorderColor: "#71C898",
     pointBackgroundColor: "#2D9A5E",
     pointBorderWidth: 1,
     pointHoverRadius: 5,
     pointHoverBackgroundColor: "#71C898",
     pointHoverBorderColor: "rgba(220,220,220,1)",
     pointHoverBorderWidth: 2,
     pointRadius: 5,
     pointHitRadius: 10,
     data: this.props.data.length > 0 ? this.props.data : [],
}],
}} 
height={ 200 } 
options={ {
    tooltips: {
       callbacks: {
           label: (tooltipItems, data) => {
               return `${currencyFormatter(tooltipItems.value)}`
           }
       }
    }
}}
/>
4

1 回答 1

1

Y 轴可以在 options => scales => yAxis => ticks 中格式化。在那里,您可以使用与工具提示相同的样式格式化标签。

    options={ 
      {
        tooltips: {
          callbacks: {
              label: (tooltipItems, data) => {
                  return `${currencyFormatter(tooltipItems.value)}`
              }
          }
        },
        scales:{
          yAxes:[
            {
              ticks: {
                callback: function(label, index, labels) {
                    return `${currencyFormatter(label)}`
                }
              },
            }
          ]
        }
      }
  }
于 2020-11-05T16:09:45.030 回答