我將 chart.js 與 React 一起使用,但我無法弄清楚為什么折線圖不適用于type: 'time',也許我可能會遺漏一些東西:Chart.js 代碼沙箱import React from "react";import { Line } from "react-chartjs-2";const startDate = new Date(2020, 4, 20);const values = JSON.parse(json).responses[0].rows.map(row => row.values[0]);const options = { legend: { display: false }, hover: { mode: "index", intersect: false, animationDuration: 0 }, scales: { yAxes: [{ position: "right" }], xAxes: [ { gridLines: { display: false }, type: "time", time: { parser: "MMM D", unit: "day", unitStepSize: 5, displayFormats: { day: "MMM D" } }, ticks: { min: startDate, //May 20 max: new Date() } } ] }, tooltips: { mode: "x-axis" }};const data = { datasets: [ { label: "data", fill: false, data: values, backgroundColor: "pink", borderWidth: 2, lineTension: 0, borderColor: "pink", hoverBorderWidth: 2, pointBorderColor: "rgba(0, 0, 0, 0)", pointBackgroundColor: "rgba(0, 0, 0, 0)", pointHoverBackgroundColor: "#fff", pointHoverBorderColor: "pink", showLine: true } ]};const LineChart = () => { return ( <div style={{ maxWidth: 1024, margin: "32px auto" }}> <Line data={data} options={options} /> </div> );};export default LineChart;
折線圖不適用于類型時間 chart.js
元芳怎么了
2022-12-09 19:47:24