【问题标题】:Title is undefined in react-chart标题在反应图中未定义
【发布时间】:2021-06-11 06:06:00
【问题描述】:

我正在构建一个 covid-19 跟踪器,但是当使用反应图表在图表上显示数据时,标题是未定义的

这是我的图表代码

 <div >
  {data?.length > 0 && (
    <Line
      data={{
        datasets: [
          {
            backgroundColor: "rgba(204, 16, 52, 0.5)",
            borderColor: "#CC1034",
            data: data,
          },
        ],
      }}
      options={options}
    />
  )}
</div>

这些是我的选项参数

 const options = {
  legend: {
    display: false,
  },
  elements: {
    point: {
      radius: 0,
    },
  },
  maintainAspectRatio: false,
  tooltips: {
    mode: "index",
    intersect: false,
    callbacks: {
      label: function (tooltipItem, data) {
        return numeral(tooltipItem.value).format("+0,0");
      },
    },
  },
  scales: {
    xAxes: [
      {
        type: "time",
        time: {
          format: "MM/DD/YY",
          tooltipFormat: "ll",
        },
      },
    ],
    yAxes: [
      {
        gridLines: {
          display: false,
        },
        ticks: {
          // Include a dollar sign in the ticks
          callback: function (value, index, values) {
            return numeral(value).format("0a");
          },
        },
      },
    ],
  },
};

虽然 legend 设置为 false,但我收到了错误消息。 请告诉我哪里出错了,这会很有帮助。

图表的图像。

【问题讨论】:

    标签: reactjs material-ui react-chartjs react-chartjs-2


    【解决方案1】:

    这里需要传递label属性

    data={{
      datasets: [
        {
          backgroundColor: "rgba(204, 16, 52, 0.5)",
          borderColor: "#CC1034",
          data: data,
          label: "your label" // <-- pass this 
        },
      ],
    }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-22
      • 2018-12-09
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 2021-08-21
      • 2018-09-17
      相关资源
      最近更新 更多