Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/06-finished/src/components/Chart/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Chart = (props) => {
value={dataPoint.value}
maxValue={totalMaximum}
label={dataPoint.label}
totalValue={props.totalValue}
/>
))}
</div>
Expand Down
2 changes: 1 addition & 1 deletion code/06-finished/src/components/Chart/ChartBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ChartBar = (props) => {
let barFillHeight = '0%';

if (props.maxValue > 0) {
barFillHeight = Math.round((props.value / props.maxValue) * 100) + '%';
barFillHeight = Math.round((props.value / props.totalValue) * 100) + '%';
}

return (
Expand Down
4 changes: 3 additions & 1 deletion code/06-finished/src/components/Expenses/ExpensesChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ const ExpensesChart = (props) => {
{ label: 'Dec', value: 0 },
];

let totalAmount = 0;
for (const expense of props.expenses) {
const expenseMonth = expense.date.getMonth(); // starting at 0 => January => 0
chartDataPoints[expenseMonth].value += expense.amount;
totalAmount += expense.amount;
}

return <Chart dataPoints={chartDataPoints} />;
return <Chart dataPoints={chartDataPoints} totalValue={totalAmount} />;
};

export default ExpensesChart;