-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d29f349
commit 9939dfd
Showing
8 changed files
with
291 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,22 @@ | ||
import axios from 'axios'; | ||
import React from 'react'; | ||
import Plot from 'react-plotly.js'; | ||
import './App.css'; | ||
|
||
import UserByCountry from './components/UserByCountry'; | ||
import UserByGender from './components/UserByGender'; | ||
import UserBySalary from './components/UserBySalary'; | ||
|
||
export default class App extends React.Component { | ||
|
||
state = { | ||
stats: [] | ||
} | ||
|
||
componentDidMount() { | ||
axios.get(`http://localhost:8090/pie`) | ||
.then(res => { | ||
const stats = res.data.result.country; | ||
this.setState({ stats }); | ||
}) | ||
} | ||
|
||
render() { | ||
if (this.state.stats) { | ||
const countries = Object.keys(this.state.stats) | ||
const counts = Object.values(this.state.stats) | ||
|
||
return ( | ||
<div> | ||
<Plot | ||
data={ | ||
[{ | ||
y: counts, | ||
x: countries, | ||
type: 'scatter' | ||
}] | ||
} | ||
layout={{ | ||
title: 'Scatter Plot', | ||
height: 400, | ||
width: 800 | ||
}} | ||
/> | ||
<Plot | ||
data={ | ||
[{ | ||
values: counts, | ||
labels: countries, | ||
type: 'pie' | ||
}] | ||
} | ||
layout={{ | ||
title: 'Pie Chart', | ||
height: 400, | ||
width: 800 | ||
}} | ||
/> | ||
return ( | ||
<div> | ||
<div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'center' }}> | ||
<UserByCountry /> | ||
</div> | ||
<div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'center' }}> | ||
<UserByGender /> | ||
<UserBySalary /> | ||
</div> | ||
); | ||
} else { | ||
<p>Loading....</p> | ||
} | ||
</div > | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import axios from 'axios'; | ||
import React from 'react'; | ||
import Plot from 'react-plotly.js'; | ||
|
||
|
||
export default class UserByCountry extends React.Component { | ||
|
||
state = { | ||
stats: [] | ||
} | ||
|
||
componentDidMount() { | ||
axios.get(`http://localhost:8090/pie`) | ||
.then(res => { | ||
const stats = res.data.result.country; | ||
this.setState({ stats }); | ||
}) | ||
} | ||
|
||
render() { | ||
if (this.state.stats) { | ||
const countries = Object.keys(this.state.stats) | ||
const counts = Object.values(this.state.stats) | ||
|
||
return ( | ||
<div> | ||
<h2>Userbase by Country</h2> | ||
<Plot | ||
data={ | ||
[{ | ||
y: counts, | ||
x: countries, | ||
type: 'scatter' | ||
}] | ||
} | ||
layout={{ | ||
title: 'Scatter Plot', | ||
height: 400, | ||
width: 800 | ||
}} | ||
/> | ||
<Plot | ||
data={ | ||
[{ | ||
values: counts, | ||
labels: countries, | ||
type: 'pie' | ||
}] | ||
} | ||
layout={ | ||
{ | ||
title: 'Pie Chart', | ||
height: 400, | ||
width: 800 | ||
} | ||
} | ||
/> | ||
</div> | ||
); | ||
} else { | ||
<p>Loading....</p> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import axios from 'axios'; | ||
import React from 'react'; | ||
import Plot from 'react-plotly.js'; | ||
|
||
|
||
export default class UserByGender extends React.Component { | ||
|
||
state = { | ||
stats: [] | ||
} | ||
|
||
componentDidMount() { | ||
axios.get(`http://localhost:8090/pie?field=gender`) | ||
.then(res => { | ||
const stats = res.data.result.gender; | ||
this.setState({ stats }); | ||
}) | ||
} | ||
|
||
render() { | ||
if (this.state.stats) { | ||
const genders = Object.keys(this.state.stats) | ||
const counts = Object.values(this.state.stats) | ||
|
||
return ( | ||
<div> | ||
<h2>Userbase by Gender</h2> | ||
<Plot | ||
data={ | ||
[{ | ||
values: counts, | ||
labels: genders, | ||
type: 'pie', | ||
hole: .4, | ||
}] | ||
} | ||
layout={ | ||
{ | ||
title: 'Pie Chart', | ||
height: 400, | ||
width: 800 | ||
} | ||
} | ||
/> | ||
</div> | ||
); | ||
} else { | ||
<p>Loading....</p> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import axios from 'axios'; | ||
import React from 'react'; | ||
import Plot from 'react-plotly.js'; | ||
|
||
|
||
export default class UserBySalary extends React.Component { | ||
|
||
state = { | ||
stats: [] | ||
} | ||
|
||
componentDidMount() { | ||
axios.get(`http://localhost:8090/salary-distribution`) | ||
.then(res => { | ||
const stats = res.data.result.grouped_salary; | ||
this.setState({ stats }); | ||
}) | ||
} | ||
|
||
render() { | ||
if (this.state.stats) { | ||
const salaries = Object.keys(this.state.stats) | ||
const counts = Object.values(this.state.stats) | ||
|
||
return ( | ||
<div style={{ paddingLeft: '100px' }}> | ||
<h2>Userbase by Salary</h2> | ||
<Plot | ||
data={ | ||
[{ | ||
y: counts, | ||
x: salaries, | ||
type: 'scatter' | ||
}] | ||
} | ||
layout={{ | ||
title: 'Scatter Plot', | ||
height: 400, | ||
width: 800 | ||
}} | ||
/> | ||
</div> | ||
); | ||
} else { | ||
<p>Loading....</p> | ||
} | ||
} | ||
} |
Oops, something went wrong.