Skip to content

Commit a6e1398

Browse files
Add and Style BarCharts
1 parent f543f2f commit a6e1398

File tree

5 files changed

+75
-22
lines changed

5 files changed

+75
-22
lines changed

src/components/Barchart.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { Component } from "react";
2+
import {
3+
BarChart,
4+
Bar,
5+
XAxis,
6+
YAxis,
7+
CartesianGrid,
8+
Tooltip,
9+
Legend,
10+
} from "recharts";
11+
12+
export default class Barchart extends Component {
13+
render() {
14+
const { data, isLoading, dataKey, stroke } = this.props;
15+
// const updatedData = data.slice(25, -1);
16+
const result = data.map((dataItem) => {
17+
return {
18+
date: dataItem.day.slice(5),
19+
...dataItem.summary,
20+
confirmed: dataItem.summary.total,
21+
active:
22+
dataItem.summary.total -
23+
(dataItem.summary.discharged + dataItem.summary.deaths),
24+
};
25+
});
26+
return (
27+
<div className="charts">
28+
{!isLoading && (
29+
<BarChart
30+
width={350}
31+
height={150}
32+
data={result}
33+
margin={{ top: 5, right: 30, left: 20, bottom: 5 }}
34+
>
35+
<XAxis dataKey="date" />
36+
<YAxis />
37+
<Tooltip />
38+
{/* <Legend /> */}
39+
<Bar dataKey={dataKey} fill={stroke} />
40+
</BarChart>
41+
)}
42+
</div>
43+
);
44+
}
45+
}

src/components/Charts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class Charts extends Component {
4141
>
4242
<XAxis dataKey="date" />
4343
<YAxis />
44-
<CartesianGrid strokeDasharray="3 3" />
44+
{/* <CartesianGrid strokeDasharray="3 3" /> */}
4545
<Tooltip />
4646
<Legend
4747
wrapperStyle={{

src/components/CovidApp.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
1212
import { faSyncAlt } from "@fortawesome/free-solid-svg-icons";
1313
import "../styles/DarkModeButton.css";
1414
import MapSection from "./MapSection";
15+
import Barchart from "./Barchart";
1516

1617
class CovidApp extends Component {
1718
constructor(props) {
@@ -140,65 +141,70 @@ class CovidApp extends Component {
140141
isDarkMode={isDarkMode}
141142
/>
142143
</div>
143-
<div></div>
144144
</div>
145+
{/* <Barchart
146+
data={this.state.data}
147+
isLoading={this.state.isLoading}
148+
dataKey="confirmed"
149+
stroke={colors.red}
150+
/> */}
145151
<div className={classes.chartArea}>
146152
<div className={classes.tinyChartArea}>
147153
<div className={classes.tinyChart}>
148154
<div
149155
className={classes.tinych}
150156
style={{ background: "rgba(249, 52, 94,.1)" }}
151157
>
152-
<TinyCharts
158+
<h3 style={{ color: colors.red }}>confirmed</h3>
159+
<Barchart
153160
data={this.state.data}
154161
isLoading={this.state.isLoading}
155162
dataKey="confirmed"
156163
stroke={colors.red}
157164
/>
158165
</div>
159-
<h3 style={{ color: colors.red }}>confirmed</h3>
160166
</div>
161167
<div className={classes.tinyChart}>
162168
<div
163169
className={classes.tinych}
164170
style={{ background: "rgba(250, 100, 0,.1)" }}
165171
>
166-
<TinyCharts
172+
<h3 style={{ color: colors.orange }}>active</h3>
173+
<Barchart
167174
data={this.state.data}
168175
isLoading={this.state.isLoading}
169176
dataKey="active"
170177
stroke={colors.orange}
171178
/>
172179
</div>
173-
<h3 style={{ color: colors.orange }}>active</h3>
174180
</div>
175181
<div className={classes.tinyChart}>
176182
<div
177183
className={classes.tinych}
178184
style={{ background: "rgba(28, 177, 66,.1)" }}
179185
>
180-
<TinyCharts
186+
<h3 style={{ color: colors.green }}>Recovered</h3>
187+
<Barchart
181188
data={this.state.data}
182189
isLoading={this.state.isLoading}
183190
dataKey="discharged"
184191
stroke={colors.green}
185192
/>
186193
</div>
187-
<h3 style={{ color: colors.green }}>Recovered</h3>
188194
</div>
189195
<div className={classes.tinyChart}>
190196
<div
191197
className={classes.tinych}
192198
style={{ background: "rgba(98, 54, 255,.1)" }}
193199
>
194-
<TinyCharts
200+
<h3 style={{ color: colors.purple }}>Deceased</h3>
201+
<Barchart
195202
data={this.state.data}
196203
isLoading={this.state.isLoading}
197204
dataKey="deaths"
198205
stroke={colors.purple}
199206
/>
200207
</div>
201-
<h3 style={{ color: colors.purple }}>Deceased</h3>
202208
</div>
203209
</div>
204210
<Charts data={this.state.data} isLoading={this.state.isLoading} />

src/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ body {
1919
font-size: 1.6rem;
2020
line-height: 1.7;
2121
color: #1A1053;
22+
/* background-color: #fff; */
2223
background-color: rgb(245, 245, 245);
2324
/* background-color: rgba(185, 185, 185, 0.281); */
2425
}

src/styles/DisplayPanelsStyles.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ export default {
1616
if (props.isMiniPanel) {
1717
return null;
1818
}
19-
let color;
20-
let title = props.title.toLowerCase();
21-
if (title === "recovered") {
22-
color = "rgb(28, 177, 66,.2)";
23-
} else if (title === "deceased") {
24-
color = "rgb(98, 54, 25,.2)";
25-
} else if (title === "active") {
26-
color = "rgb(250, 100, 0,.2)";
27-
} else if (title === "confirmed") {
28-
color = "rgb(249, 52, 94,.2)";
29-
}
30-
return `0 .5rem 3rem ${color}`;
19+
return "0 1.5rem 3rem rgba(0, 0, 0, 0.1)";
20+
// let color;
21+
// let title = props.title.toLowerCase();
22+
// if (title === "recovered") {
23+
// color = "rgb(28, 177, 66,.2)";
24+
// } else if (title === "deceased") {
25+
// color = "rgb(98, 54, 25,.2)";
26+
// } else if (title === "active") {
27+
// color = "rgb(250, 100, 0,.2)";
28+
// } else if (title === "confirmed") {
29+
// color = "rgb(249, 52, 94,.2)";
30+
// }
31+
// return `0 .5rem 3rem ${color}`;
3132
},
3233
},
3334

0 commit comments

Comments
 (0)