Example How to display data on top of line chart
issues faced while implementing:
chartjs Plugin "chartjs-plugin-datalabels:1.0.0" import is throwed below error
TypeError : Cannot read property 'extend' of undefined.
Above error resolved by changing the labels plugin package to test version 2.0.0-rc.1
Link to codesandbox will find HERE
A similar question was asked here but the solutions couldn't resolve my issue.
Any kind of help will much be appreciated.
import React, { Fragment } from "react";
import { Line } from "react-chartjs-2";
import "chartjs-plugin-datalabels";
const styles = {
dangerColor: {
color: "red"
},
geen: {
color: "green"
}
};
const data = {
labels: ["Jan", "Feb", "Mar", "Apr", "May"],
datasets: [
{
label: "Avg interest by month",
data: [0.7, 0.81, 0.71, 0.87, 0.9],
fill: false,
backgroundColor: "transparent",
borderColor: "#06a1e1",
tension: 0.1,
borderWidth: 4
}
]
};
const options = {
maintainAspectRatio: false,
scales: {
x: {
grid: {
display: false
}
},
y: {
display: false,
grid: {
display: false
}
}
},
plugins: {
legend: {
display: false
},
title: {
display: true,
text: "Avg interest by month (days)",
padding: {
bottom: 30
},
weight: "bold",
color: "#00325c",
font: {
size: 13
},
align: "start"
},
datalabels: {
display: true,
color: "white"
}
}
};
const LineChart = () => (
<Fragment>
<div style={{ height: "300px" }}>
<Line data={data} options={options} />
</div>
</Fragment>
);
export default LineChart;
This is how my Package.json dependencies looks like
{
"chart.js": "^3.3.2",
"chartjs-plugin-datalabels": "^2.0.0-rc.1",
"react": "^17.0.2",
"react-chartjs-2": "^3.0.3",
"react-dom": "^17.0.2",
"react-scripts": "^4.0.3",
"web-vitals": "^1.1.2"
}