-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainIncomes.js
52 lines (40 loc) · 1.22 KB
/
MainIncomes.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
import styled from "@emotion/styled";
import Image from "next/image";
import Chart from "./chart";
import 'chart.js/auto';
import { Line, Pie } from "react-chartjs-2";
import useMainIncomesService from "../hooks/useMainIncomesService";
const MainIncomes = function ({user: userId} ) {
return <MainIncomesPic userId = {userId}></MainIncomesPic>;
};
const MainIncomesPic = function ({userId}) {
//console.log(userId);
var orders = useMainIncomesService(userId)
console.log(orders);
if(orders.length >= 3) orders = orders.slice(0,3);
console.log(orders);
var labels = orders.map(order => order.name);
var labels = labels.slice(0, orders.length);
var colors = ["#FF6384", "#36A2EB", "#FFCE56"];
var colors = colors.slice(0, orders.length);
var price = orders.map(order => order.price);
//console.log(price)
//console.log(labels);
const data = {
labels: labels,
datasets: [
{
data: price,
backgroundColor: colors,
hoverBackgroundColor: colors,
},
],
};
return (
<Chart>
<h2>購買金額圓餅圖</h2>
<Pie data={data} width={400} height={400} />
</Chart>
);
};
export default MainIncomes;