-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c973551
commit f0a933f
Showing
1 changed file
with
104 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,116 @@ | ||
// components/LineChart.js | ||
// // components/LineChart.js | ||
// import React from "react"; | ||
// import { Line } from "react-chartjs-2"; | ||
// import { | ||
// Chart as ChartJS, | ||
// CategoryScale, | ||
// LinearScale, | ||
// PointElement, | ||
// LineElement, | ||
// Title, | ||
// Tooltip, | ||
// Legend, | ||
// } from 'chart.js' | ||
// import { Chart } from 'react-chartjs-2' | ||
|
||
// ChartJS.register( | ||
// CategoryScale, | ||
// LinearScale, | ||
// PointElement, | ||
// LineElement, | ||
// Title, | ||
// Tooltip, | ||
// Legend | ||
// ) | ||
|
||
// function LineChart({ x, y, label }) { | ||
|
||
// const state = { | ||
// labels: x, | ||
// datasets: [ | ||
// { | ||
// label: label, | ||
// fill: true, | ||
// lineTension: 0.5, | ||
// backgroundColor: 'rgba(75,192,192,1)', | ||
// borderColor: 'rgba(0,0,0,1)', | ||
// borderWidth: 2, | ||
// data: y | ||
// } | ||
// ] | ||
// } | ||
// return ( | ||
// <div> | ||
// <Line | ||
// data={state} | ||
// options={{ | ||
// legend:{ | ||
// display:true, | ||
// position:'right' | ||
// } | ||
// }} | ||
// /> | ||
// </div> | ||
// ); | ||
// } | ||
// export default LineChart; | ||
|
||
import React from "react"; | ||
import { Line } from "react-chartjs-2"; | ||
import { Bar } from "react-chartjs-2"; | ||
import { | ||
Chart as ChartJS, | ||
CategoryScale, | ||
LinearScale, | ||
PointElement, | ||
LineElement, | ||
Title, | ||
Tooltip, | ||
Legend, | ||
} from 'chart.js' | ||
import { Chart } from 'react-chartjs-2' | ||
|
||
ChartJS.register( | ||
CategoryScale, | ||
LinearScale, | ||
PointElement, | ||
LineElement, | ||
Title, | ||
Tooltip, | ||
Legend | ||
) | ||
Chart as ChartJS, | ||
CategoryScale, | ||
LinearScale, | ||
Title, | ||
Tooltip, | ||
Legend, | ||
BarElement, // Correct import for Bar chart | ||
} from "chart.js"; | ||
import { Chart } from "react-chartjs-2"; | ||
|
||
function LineChart({ x, y, label }) { | ||
ChartJS.register(CategoryScale, LinearScale, Title, Tooltip, Legend, BarElement); | ||
|
||
function LineChart({ x, y, label }) { | ||
const state = { | ||
labels: x, | ||
datasets: [ | ||
{ | ||
label: label, | ||
fill: true, | ||
lineTension: 0.5, | ||
backgroundColor: 'rgba(75,192,192,1)', | ||
borderColor: 'rgba(0,0,0,1)', | ||
borderWidth: 2, | ||
data: y | ||
} | ||
] | ||
} | ||
backgroundColor: "rgba(75,192,192,0.6)", // Adjust the color as needed | ||
borderColor: "rgba(0,0,0,1)", | ||
borderWidth: 1, | ||
data: y, | ||
}, | ||
], | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Line | ||
data={state} | ||
options={{ | ||
legend:{ | ||
display:true, | ||
position:'right' | ||
} | ||
}} | ||
/> | ||
</div> | ||
); | ||
<Bar | ||
data={state} | ||
options={{ | ||
scales: { | ||
x: { | ||
beginAtZero: true, // Adjust as needed | ||
}, | ||
y: { | ||
beginAtZero: true, // Adjust as needed | ||
}, | ||
}, | ||
plugins: { | ||
legend: { | ||
display: true, | ||
position: "right", | ||
}, | ||
title: { | ||
display: true, | ||
text: "Bar Chart Example", // Adjust the title as needed | ||
}, | ||
}, | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
export default LineChart; | ||
|
||
export default LineChart; |