-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathChart.jsx
More file actions
80 lines (73 loc) · 2.01 KB
/
Copy pathChart.jsx
File metadata and controls
80 lines (73 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React, { Component } from "react";
import { connect } from "react-redux";
// import Highcharts from "highcharts";
// import HighchartsReact from "highcharts-react-official";
import { Bar } from "react-chartjs-2";
import { GoGraph } from "react-icons/go";
import {
fetchCoronaStatistics,
} from "../actions";
import { MAP_STYLE_ACTION, MAP_FLY_ACTION } from "../actions/constants";
class Chart extends Component {
state = {};
componentDidMount() {
this.props.fetchCoronaStatistics();
}
renderStatistics() {
var data = JSON.parse(JSON.stringify(this.props.statistics)).results;
if (data.country_statistics !== undefined) {
var totalConfirmed = data.total_confirmed;
var totalDeaths = data.total_deaths;
var totalRecovered = data.total_recovered;
var date = data.last_date_updated;
var statistics = data.country_statistics;
let cases = [];
let country = [];
var x = statistics.map((e) => {
if (e.confirmed > 10000) {
country.push(e.country);
cases.push(e.confirmed);
}
});
return {
labels: country,
datasets: [
{
label: "Confirmed cases",
backgroundColor: "rgb(182, 109, 41)",
borderColor: "rgb(182, 109, 41)",
borderWidth: 1,
data: cases,
},
],
};
}
}
render() {
return (
<div className="chartcontainer">
<Bar
data={this.renderStatistics()}
options={{
title: {
display: true,
text: "Total confirmed cases",
fontSize: 20,
},
legend: {
display: true,
position: "right",
},
}}
/>
</div>
);
}
}
const stateProps = (state) => ({
statistics: state.statistics,
});
const dispatchProps = (dispatch) => ({
fetchCoronaStatistics: () => dispatch(fetchCoronaStatistics()),
});
export default connect(stateProps, dispatchProps)(Chart);