fix🛠️: 日期排序bug & pie样式更改

This commit is contained in:
clz 2022-09-13 15:29:37 +08:00
parent 7afb38b831
commit 8460b89711
5 changed files with 65 additions and 35 deletions

View File

@ -1,6 +1,6 @@
#root { #root {
height: 100%; height: 100%;
max-width: 1280px; /* max-width: 1280px; */
margin: 0 auto; margin: 0 auto;
/* padding: 2rem; */ /* padding: 2rem; */
/* text-align: center; */ /* text-align: center; */

View File

@ -1,10 +1,12 @@
import { import {
useRef, useRef,
useMemo, useMemo,
useEffect useEffect,
useCallback
} from 'react'; } from 'react';
import echarts, { ECOption } from '../config'; import echarts, { ECOption } from '../config';
import styles from "./indx.module.scss" import styles from "./indx.module.scss"
import dayjs from "dayjs"
type BarData = { type BarData = {
x: string | number x: string | number
@ -21,6 +23,13 @@ export const Bar = (props: IProps) => {
const { data, title, subTitle } = props; const { data, title, subTitle } = props;
// 获取数据 // 获取数据
const chartRef = useRef<HTMLDivElement>(null); const chartRef = useRef<HTMLDivElement>(null);
const colors = useCallback((value: number) => {
if (value < 50) { return "#008000" }
else if (value < 100) { return "#FFA500" }
else { return "#8B0000" }
}, [])
const option: ECOption = useMemo(() => { const option: ECOption = useMemo(() => {
return { return {
title: { title: {
@ -30,20 +39,29 @@ export const Bar = (props: IProps) => {
}, },
xAxis: { xAxis: {
type: 'category', type: 'category',
data: data.map(item => item.x), data: data.map(item => {
return dayjs(item.x).format("MM-DD")
}),
}, },
yAxis: { yAxis: {
type: "value" type: "value"
}, },
series: [ series: [
{ {
data: data.map(item => item.y), data: data.map(item => {
return {
value: item.y,
itemStyle: {
color: colors(item.y)
}
}
}),
type: "bar", type: "bar",
label: { label: {
show: true, show: true,
position: "top", position: "top",
margin: 8 margin: 8
} },
}, },
], ],
tooltip: { tooltip: {

View File

@ -43,16 +43,13 @@ export default function Pie(props: IProps) {
{ {
// name: `${year}-${month}`, // name: `${year}-${month}`,
type: "pie", type: "pie",
data: data.map(item => { radius: ['40%', '70%'],
return { // roseType: "radius",
name: item.x,
value: item.y
}
}),
radius: [20, 100],
roseType: "radius",
itemStyle: { itemStyle: {
borderRadius: 5 borderRadius: 10,
borderColor: '#fff',
borderWidth: 2,
}, },
label: { label: {
show: true, show: true,
@ -65,6 +62,12 @@ export default function Pie(props: IProps) {
show: true show: true
} }
}, },
data: data.map(item => {
return {
name: item.x,
value: item.y
}
}),
}, },
], ],
} }

View File

@ -9,18 +9,27 @@ import Pie from "../../components/charts/pie";
import { Card, DatePicker, Radio, Space } from "antd"; import { Card, DatePicker, Radio, Space } from "antd";
import moment from 'moment'; import moment from 'moment';
import 'moment/locale/zh-cn'; import 'moment/locale/zh-cn';
import dayjs from 'dayjs'
const Home = () => { const Home = () => {
const billStore = useContext(BillContext) const billStore = useContext(BillContext)
const transformer = (record: Record<string, IBill[]>) => { const transformer = (record: Record<string, IBill[]>) => {
return R.map((key: string) => { const funcs = R.compose(
R.sort((a: { x: string, y: number }, b) => {
const date1 = dayjs(a.x).toDate().getTime()
const date2 = dayjs(b.x).toDate().getTime()
return date1 - date2
}),
R.map((key: string) => {
const moneys = record[key].map(bill => bill.money) const moneys = record[key].map(bill => bill.money)
return { return {
x: key, x: key,
y: Number(R.sum(moneys).toFixed(2)), y: Number(R.sum(moneys).toFixed(2)),
} }
})(R.keys(record)) }))
return funcs(R.keys(record))
} }
const now = new Date(); const now = new Date();

View File

@ -1,6 +1,6 @@
import {Button, DatePicker, Input, InputNumber, message, Radio, Select, Space, Table, Tag} from "antd"; import {Button, DatePicker, Input, InputNumber, message, Radio, Select, Space, Table, Tag} from "antd";
import {ArrowDownOutlined, CloudUploadOutlined, DeleteOutlined,} from "@ant-design/icons"; import {ArrowDownOutlined, CloudUploadOutlined, DeleteOutlined,} from "@ant-design/icons";
import {useCallback, useContext, useEffect, useMemo, useRef, useState} from "react"; import {useContext, useEffect, useRef, useState} from "react";
import {BillType, EmptyBill, IBill} from "../../model"; import {BillType, EmptyBill, IBill} from "../../model";
import moment from "moment/moment"; import moment from "moment/moment";
import {BillContext} from "../../store"; import {BillContext} from "../../store";