Skip to content

Commit 406834e

Browse files
committed
change from bar graph to line graph
1 parent aaa2697 commit 406834e

File tree

2 files changed

+22
-40
lines changed

2 files changed

+22
-40
lines changed

src/components/Transaction/TransactionStats.jsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import {
1111
CartesianGrid,
1212
Tooltip,
1313
Legend,
14+
LineChart,
15+
Line,
1416
} from 'recharts';
17+
1518
import { isDate } from 'moment';
1619
import API from '../../apis/API'; // library for AJAX functions
1720
import Header, { HeaderPadding } from '../Navigation/Header';
@@ -46,27 +49,27 @@ function TransactionStats() {
4649
startDate,
4750
endDate,
4851
);
49-
console.log(salesInRange);
52+
5053
const incomeByDay = dataUtil.getIncomeByDay(salesInRange);
51-
console.log(incomeByDay[0]);
5254

5355
const renderPlot = () => {
5456
if (loading) return <ReactLoading color="#e26d5c" />;
55-
return (
56-
<BarChart
57-
width={600}
58-
height={300}
59-
data={salesInRange}
60-
margin={{ top: 5, right: 30, left: 20, bottom: 5 }}
61-
>
62-
<CartesianGrid strokeDasharray="3 3" />
63-
<XAxis dataKey="date" />
64-
<YAxis />
65-
<Tooltip />
66-
<Legend />
67-
<Bar dataKey="price" fill="#8884d8" />
68-
</BarChart>
69-
);
57+
if (incomeByDay.length > 0)
58+
return (
59+
<div>
60+
<LineChart width={600} height={400} data={incomeByDay}>
61+
<CartesianGrid strokeDasharray="3 3" />
62+
<XAxis label="Date" dataKey="date" interval="preserveEnd" />
63+
<YAxis label="Income ($)" interval="preserveEnd" />
64+
<Line
65+
type="monotone"
66+
dataKey="income"
67+
stroke="#8884d8"
68+
activeDot={{ r: 8 }}
69+
/>
70+
</LineChart>
71+
</div>
72+
);
7073
};
7174

7275
const dateInputs = () => {
@@ -96,7 +99,7 @@ function TransactionStats() {
9699
);
97100
};
98101

99-
const filteredData = () => {
102+
const filteredList = () => {
100103
if (loading) return <ReactLoading color="#e26d5c" />;
101104
return (
102105
<>
@@ -116,7 +119,7 @@ function TransactionStats() {
116119
<HeaderPadding />
117120
<div className="SalesPlot">{renderPlot()}</div>
118121
<div className="DateInputs">{dateInputs()}</div>
119-
<div className="FilteredData">{filteredData()}</div>
122+
<div className="FilteredData">{filteredList()}</div>
120123
</div>
121124
);
122125
}

src/components/Transaction/dataUtil.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,6 @@ const getIncomeByDay = (sales) => {
4848
return incomeByDay;
4949
};
5050

51-
// const getIncomeByDay = (sales) => {
52-
// var holder = {};
53-
// sales.forEach( (sale) => {
54-
// let day = getSimpleDate(sale);
55-
// if (holder.hasOwnProperty(day)) {
56-
// holder[day] = holder[day] + getNetIncome(sale);
57-
// } else {
58-
// holder[day] = getNetIncome(sale)
59-
// }
60-
// });
61-
62-
// var incomeByDay = [];
63-
64-
// for (let day in holder) {
65-
// incomeByDay.push({date: new Date(day), income: holder[day]});
66-
// }
67-
68-
// return incomeByDay;
69-
70-
// }
71-
7251
module.exports = {
7352
getSales,
7453
filterByDate,

0 commit comments

Comments
 (0)