11import "./styles.css" ;
2- import { Line } from "react-chartjs-2" ;
2+ import { Line , Bar } from "react-chartjs-2" ;
33import { useState , useEffect } from "react" ;
44import axiosBaseUrl from "../../../Axios/axios" ;
55import { useDispatch , useSelector } from "react-redux" ;
@@ -10,6 +10,7 @@ import {
1010 LinearScale ,
1111 PointElement ,
1212 LineElement ,
13+ BarElement ,
1314 Title ,
1415 Tooltip ,
1516 Legend ,
@@ -20,10 +21,11 @@ ChartJS.register(
2021 LinearScale ,
2122 PointElement ,
2223 LineElement ,
24+ BarElement ,
2325 Title ,
2426 Tooltip ,
2527 Legend ,
26- Filler ,
28+ Filler
2729) ;
2830
2931const ClientDashboard = ( ) => {
@@ -67,7 +69,12 @@ const ClientDashboard = () => {
6769 }
6870
6971 if ( ! dashboardData ) {
70- return < div > No dashboard data available.</ div > ;
72+ return (
73+ < div className = "spinner-container" >
74+ < div className = "spinner" > </ div >
75+ < p > Loading dashboard data...</ p >
76+ </ div >
77+ ) ;
7178 }
7279
7380 const powerUsageData = {
@@ -78,7 +85,7 @@ const ClientDashboard = () => {
7885 data : Object . values ( dashboardData . powerUsagePerDay ) ,
7986 fill : true ,
8087 backgroundColor : "rgba(75, 192, 192, 0.6)" ,
81- borderColor : "#28a745" , // Bootstrap success color
88+ borderColor : "#28a745" ,
8289 pointBackgroundColor : "#28a745" ,
8390 pointBorderColor : "#fff" ,
8491 tension : 0.3 ,
@@ -91,22 +98,28 @@ const ClientDashboard = () => {
9198 datasets : [
9299 {
93100 label : "Cumulative Power Usage (in Kilowatts)" ,
94- data : Object . values ( dashboardData . cumulativePowerUsage ) ,
95- fill : true ,
96- backgroundColor : "rgba(255, 193, 7, 0.6)" , // Bootstrap warning color
101+ data : Object . values ( dashboardData . cumulativePowerUsage ) . map (
102+ ( arr ) => Math . max ( ...arr )
103+ ) ,
104+ backgroundColor : "rgba(255, 193, 7, 0.6)" ,
97105 borderColor : "#ffc107" ,
98- pointBackgroundColor : "#ffc107" ,
99- pointBorderColor : "#fff" ,
100- tension : 0.3 ,
106+ borderWidth : 1 ,
101107 } ,
102108 ] ,
103109 } ;
104110
105111 const chartOptions = {
106112 responsive : true ,
113+ maintainAspectRatio : false ,
114+ layout : {
115+ padding : {
116+ top : 0 ,
117+ bottom : 0 ,
118+ } ,
119+ } ,
107120 plugins : {
108121 legend : {
109- position : "top " ,
122+ position : "bottom " ,
110123 } ,
111124 title : {
112125 display : true ,
@@ -127,6 +140,8 @@ const ClientDashboard = () => {
127140 } ,
128141 } ,
129142 y : {
143+ beginAtZero : true ,
144+ min : 0 ,
130145 title : {
131146 display : true ,
132147 text : "Kilowatts" ,
@@ -135,7 +150,6 @@ const ClientDashboard = () => {
135150 grid : {
136151 borderColor : "#eee" ,
137152 } ,
138- beginAtZero : true ,
139153 } ,
140154 } ,
141155 } ;
@@ -154,10 +168,6 @@ const ClientDashboard = () => {
154168 ...chartOptions ,
155169 plugins : {
156170 ...chartOptions . plugins ,
157- title : {
158- ...chartOptions . plugins . title ,
159- text : "Power Usage per Day" ,
160- } ,
161171 } ,
162172 } }
163173 />
@@ -169,16 +179,12 @@ const ClientDashboard = () => {
169179 < div className = "chart-widget" >
170180 < h3 > Cumulative Power Usage Per Day</ h3 >
171181 { Object . keys ( cumulativePowerUsageData . labels ) . length > 0 ? (
172- < Line
182+ < Bar
173183 data = { cumulativePowerUsageData }
174184 options = { {
175185 ...chartOptions ,
176186 plugins : {
177187 ...chartOptions . plugins ,
178- title : {
179- ...chartOptions . plugins . title ,
180- text : "Cumulative Power Usage Per Day" ,
181- } ,
182188 } ,
183189 } }
184190 />
0 commit comments