Skip to content

Commit

Permalink
implementing bar chart
Browse files Browse the repository at this point in the history
  • Loading branch information
batool-ahmed authored Aug 13, 2023
1 parent c973551 commit f0a933f
Showing 1 changed file with 104 additions and 44 deletions.
148 changes: 104 additions & 44 deletions src/components/LineChart.js
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;

0 comments on commit f0a933f

Please sign in to comment.