import React from "react";
import { Line } from "react-chartjs-2";
// "chart.js": "^2.9.4",
// "react-chartjs-2": "^2.11.1"
const ext_data = [11, 19, 3, 5, 2, 3, 14, 19];
const ll = Array.from(Array(ext_data.length).keys());
const data = {
labels: ll,
datasets: [
{
label: "Profit$",
data: ext_data,
fill: false,
backgroundColor: "rgb(255, 99, 132)",
borderColor: "rgba(255, 99, 132, 0.4)"
}
]
};
const options = {
scales: {
yAxes: [
{
ticks: {
beginAtZero: true
}
}
]
}
};
const LineChart = () => (
<>
<div className = "header">
<h1 className = "title">Profit Trend</h1>
<div className = "links"></div>
</div>
<Line data = {data} options = {options} />
</>
);
export default LineChart;
Я пытаюсь добавить имя оси X: «время» и имя оси Y: «количество автомобилей». Я зашел в документацию: https://www.chartjs.org/docs/latest/axes/labelling.html Тем не менее, я не смог найти что-то полезное. Спасибо за ваше время.





В react-chartjs-2, чтобы добавить свой заголовок к вашей оси, просто добавьте это в свой массив опций yAxes (options.scales.yAxes[]):
scaleLabel: {
display: true,
labelString: "number of cars",
fontColor: "color you want",
}
то же самое для ваших xAxes.