-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPieChart.js
57 lines (52 loc) · 1.59 KB
/
PieChart.js
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
import React, { Component } from "react";
import { Pie } from "react-chartjs-2";
export default class App extends Component {
state = {
dataPie: {
datasets: [{
label: 'Rating for intern',
data: [50, 70, 20]
}],
},
first: "",
second: "",
}
handleSubmit = () => {
const { dataPie } = this.state;
this.setState({
dataPie: {
...dataPie,
datasets: [{
...dataPie.datasets,
data: [...dataPie.datasets[0].data,
this.state.first, this.state.second]
}]
}
})
}
handleChange = (evt) => {
let a = parseInt(evt.target.value)
this.setState({
[evt.target.name]: a,
})
}
render() {
const { data, dataPie } = this.state;
console.log(dataPie);
return (
<React.Fragment>
<input type="number"
value={this.setState.first}
name="first"
onChange={(evt) => this.handleChange(evt)} />
<input type="number"
value={this.setState.second}
name="second"
onChange={(evt) => this.handleChange(evt)} />
<button onClick={() => this.handleSubmit()}>Add Data</button>
<h1>pie chart</h1>
<Pie data={dataPie} />
</React.Fragment>
)
}
}