Skip to content

Commit e41d172

Browse files
committed
update echart
1 parent 00657b0 commit e41d172

File tree

9 files changed

+131
-47
lines changed

9 files changed

+131
-47
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"antd": "^4.16.11",
2727
"axios": "^0.19.0",
2828
"date-fns": "^2.23.0",
29-
"echarts": "^4.2.0-rc.2",
29+
"echarts": "^5.2.1",
3030
"lodash": "^4.17.21",
3131
"mobx": "^5.15.0",
3232
"mobx-react": "^6.1.4",
@@ -43,7 +43,6 @@
4343
"@babel/preset-env": "^7.12.11",
4444
"@babel/preset-react": "^7.12.10",
4545
"@babel/preset-typescript": "^7.12.7",
46-
"@types/echarts": "^4.1.3",
4746
"@types/lodash": "^4.14.172",
4847
"@types/quill": "^2.0.1",
4948
"@types/react": "^17.0.17",

src/pages/lottery/ballChart.tsx

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@ import * as React from 'react'
22
import {inject, observer} from 'mobx-react'
33
import { Row, Col, Form, Button } from 'antd'
44
import { IBall } from '@models/ball'
5-
import * as Echart from 'echarts/lib/echarts'
6-
// const Echart = require('echarts/lib/echarts')
7-
// 引入柱状图
8-
require('echarts/lib/chart/bar')
9-
require('echarts/lib/chart/line')
10-
// 引入提示框和标题组件
11-
require('echarts/lib/component/tooltip')
12-
require('echarts/lib/component/title')
13-
require('echarts/lib/component/legend')
5+
import * as Echart from 'echarts/core'
6+
import { LegendComponent, TitleComponent, TooltipComponent, GridComponent } from 'echarts/components'
7+
import { BarChart, LineChart } from 'echarts/charts'
8+
import { CanvasRenderer } from 'echarts/renderers';
9+
// // 引入柱状图
10+
// require('echarts/lib/chart/bar')
11+
// require('echarts/lib/chart/line')
12+
// // 引入提示框和标题组件
13+
// require('echarts/lib/component/tooltip')
14+
// require('echarts/lib/component/title')
15+
// require('echarts/lib/component/legend')
16+
17+
Echart.use([
18+
BarChart,
19+
LineChart,
20+
LegendComponent,
21+
TitleComponent,
22+
TooltipComponent,
23+
GridComponent,
24+
CanvasRenderer
25+
])
1426

1527
@inject('ballChartStore')
1628
@observer

src/pages/stocks/history.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import React, { useState, useEffect } from 'react'
22
import { Row, Col, Form, Table, Input, Button, Spin, Select } from 'antd'
33
import { DatePicker } from 'components/datePicker'
44
import { historyColumns } from './util'
5-
import { stockHistoryPageList, StockQuery } from '../../services/stockHistory'
5+
import { stockHistoryPageList, stockHistoryTotal } from '../../services/stockHistory'
66
import { data2PageData, pageData2Params } from '../../utils/tools'
77
import { StockHistory } from '../../types/stockHistory'
88
import { debounce } from 'lodash'
99
import { stockPageList } from 'services/stock'
10+
import { StockQuery } from 'types/stock'
1011

1112
const StockHistoryList: React.FC = () => {
1213

@@ -18,6 +19,7 @@ const StockHistoryList: React.FC = () => {
1819
meta: {page: 1, pageSize: 10, total: 0}
1920
}))
2021
const [stockOpts, setStockOpts] = useState<IOption<number>[]>([])
22+
const [total, setTotal] = useState(0)
2123

2224
const onQuery = (params = pageData2Params(pageData.meta)) => {
2325
const vals = form.getFieldsValue()
@@ -50,6 +52,7 @@ const StockHistoryList: React.FC = () => {
5052

5153
useEffect(() => {
5254
onQuery()
55+
stockHistoryTotal().then(setTotal)
5356
}, [])
5457

5558

@@ -62,7 +65,8 @@ const StockHistoryList: React.FC = () => {
6265
</Form.Item>
6366
</Col>
6467
</Row>
65-
<Row justify="end">
68+
<Row justify="space-between">
69+
<div>All History:{total}</div>
6670
<Button type="primary" onClick={() => onQuery()}>Search</Button>
6771
</Row>
6872
</Form>

src/pages/stocks/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const StockList: React.FC<ICommonProps> = ({history}) => {
3434

3535

3636
return <Spin spinning={loading}>
37-
<Form form={form}>
37+
<Form className="mgb16" form={form}>
3838
<Row gutter={16}>
3939
<Col span={6}>
4040
<Form.Item name="code">

src/pages/stocks/kLine.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { Spin } from 'antd'
2+
import React, { useState, useEffect, useRef } from 'react'
3+
import * as echarts from 'echarts/core';
4+
import {
5+
DatasetComponent,
6+
DatasetComponentOption,
7+
TitleComponent,
8+
TitleComponentOption,
9+
ToolboxComponent,
10+
ToolboxComponentOption,
11+
TooltipComponent,
12+
TooltipComponentOption,
13+
GridComponent,
14+
GridComponentOption,
15+
VisualMapComponent,
16+
VisualMapComponentOption,
17+
DataZoomComponent,
18+
DataZoomComponentOption
19+
} from 'echarts/components';
20+
import {
21+
CandlestickChart,
22+
CandlestickSeriesOption,
23+
BarChart,
24+
BarSeriesOption
25+
} from 'echarts/charts';
26+
import { CanvasRenderer } from 'echarts/renderers';
27+
28+
echarts.use([
29+
DatasetComponent,
30+
TitleComponent,
31+
ToolboxComponent,
32+
TooltipComponent,
33+
GridComponent,
34+
VisualMapComponent,
35+
DataZoomComponent,
36+
CandlestickChart,
37+
BarChart,
38+
CanvasRenderer
39+
]);
40+
41+
type EChartsOption = echarts.ComposeOption<
42+
| DatasetComponentOption
43+
| TitleComponentOption
44+
| ToolboxComponentOption
45+
| TooltipComponentOption
46+
| GridComponentOption
47+
| VisualMapComponentOption
48+
| DataZoomComponentOption
49+
| CandlestickSeriesOption
50+
| BarSeriesOption
51+
>;
52+
53+
export const DayKLineChart: React.FC<{id: string}> = ({id}) => {
54+
55+
const chartRef = useRef<HTMLDivElement>()
56+
57+
const [loading, setLoading] = useState(false)
58+
const [data, setData] = useState({})
59+
60+
useEffect(() => {
61+
const myChart = echarts.init(chartRef.current);
62+
}, [id])
63+
64+
return <Spin spinning={loading}>
65+
<div ref={chartRef}></div>
66+
</Spin>
67+
}

src/pages/stocks/util.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export const listColumns = (onOpts: (data: Stock) => void): ColumnProps<Stock>[]
1919
{
2020
title: 'Name',
2121
dataIndex: 'name',
22-
width: '120px',
22+
// width: '120px',
23+
render: (v, data) => <Button type="link" onClick={() => onOpts(data)}>{v}</Button>
2324
},
2425
{
2526
title: 'Code',
@@ -35,12 +36,12 @@ export const listColumns = (onOpts: (data: Stock) => void): ColumnProps<Stock>[]
3536
dataIndex: 'block',
3637
render: (v, data) => <Tag color={blockObj[data.block]}>{EBlock[data.block]}</Tag>
3738
},
38-
{
39-
title: 'Options',
40-
dataIndex: '',
41-
width: '30px',
42-
render: (v, data) => <Button type="link" onClick={() => onOpts(data)}>查看</Button>
43-
}
39+
// {
40+
// title: 'Options',
41+
// dataIndex: '',
42+
// width: '30px',
43+
// render: (v, data) => <Button type="link" onClick={() => onOpts(data)}>查看</Button>
44+
// }
4445
]
4546
}
4647

src/services/stockHistory.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import $http from '@utils/http'
22
import { pageData2Params } from '@utils/tools'
3-
import { Stock } from 'types/stock'
3+
import { StockQuery } from 'types/stock'
44
import { StockHistory } from 'types/stockHistory'
55

6-
7-
export type StockQuery = Omit<Stock & IPageParams, 'amount'>
8-
96
export const stockHistoryPageList = (params: Partial<StockQuery> = pageData2Params()) => {
107
return $http.get<any, IPageData<StockHistory>>('/api/stockhistory', { params })
8+
}
9+
10+
export const stockHistoryTotal = () => {
11+
return $http.get<any, IResponseData<number>>('/api/stockhistory/total').then(res => res.data)
1112
}

src/types/stock.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ export enum EBlock {
2525
科创板
2626
}
2727

28-
export type KeyofBlock = keyof typeof EBlock
28+
export type KeyofBlock = keyof typeof EBlock
29+
30+
31+
export type StockQuery = Omit<Stock & IPageParams, 'amount'>
32+

yarn.lock

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,13 +1110,6 @@
11101110
ejs "^2.6.1"
11111111
magic-string "^0.25.0"
11121112

1113-
"@types/echarts@^4.1.3":
1114-
version "4.9.3"
1115-
resolved "https://registry.npm.taobao.org/@types/echarts/download/@types/echarts-4.9.3.tgz?cache=0&sync_timestamp=1608263981280&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fecharts%2Fdownload%2F%40types%2Fecharts-4.9.3.tgz#8a143cf315f6ae88d0778d75a133b378974d37d5"
1116-
integrity sha1-ihQ88xX2rojQd411oTOzeJdNN9U=
1117-
dependencies:
1118-
"@types/zrender" "*"
1119-
11201113
"@types/eslint-scope@^3.7.0":
11211114
version "3.7.0"
11221115
resolved "https://registry.npm.taobao.org/@types/eslint-scope/download/@types/eslint-scope-3.7.0.tgz#4792816e31119ebd506902a482caec4951fabd86"
@@ -1279,11 +1272,6 @@
12791272
resolved "https://registry.npm.taobao.org/@types/unist/download/@types/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
12801273
integrity sha1-nAiGeYdvN061mD8VDUeHqm+zLX4=
12811274

1282-
"@types/zrender@*":
1283-
version "4.0.0"
1284-
resolved "https://registry.npm.taobao.org/@types/zrender/download/@types/zrender-4.0.0.tgz?cache=0&sync_timestamp=1605057466822&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fzrender%2Fdownload%2F%40types%2Fzrender-4.0.0.tgz#a6806f12ec4eccaaebd9b0d816f049aca6188fbd"
1285-
integrity sha1-poBvEuxOzKrr2bDYFvBJrKYYj70=
1286-
12871275
"@typescript-eslint/eslint-plugin@^4.10.0":
12881276
version "4.10.0"
12891277
resolved "https://registry.npm.taobao.org/@typescript-eslint/eslint-plugin/download/@typescript-eslint/eslint-plugin-4.10.0.tgz?cache=0&sync_timestamp=1608158895927&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40typescript-eslint%2Feslint-plugin%2Fdownload%2F%40typescript-eslint%2Feslint-plugin-4.10.0.tgz#19ed3baf4bc4232c5a7fcd32eaca75c3a5baf9f3"
@@ -3083,12 +3071,13 @@ ecc-jsbn@~0.1.1:
30833071
jsbn "~0.1.0"
30843072
safer-buffer "^2.1.0"
30853073

3086-
echarts@^4.2.0-rc.2:
3087-
version "4.9.0"
3088-
resolved "https://registry.npm.taobao.org/echarts/download/echarts-4.9.0.tgz#a9b9baa03f03a2a731e6340c55befb57a9e1347d"
3089-
integrity sha1-qbm6oD8Doqcx5jQMVb77V6nhNH0=
3074+
echarts@^5.2.1:
3075+
version "5.2.1"
3076+
resolved "https://registry.nlark.com/echarts/download/echarts-5.2.1.tgz?cache=0&sync_timestamp=1632191301834&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fecharts%2Fdownload%2Fecharts-5.2.1.tgz#bd58ec011cd82def4a714e4038ef4b73b8417bc3"
3077+
integrity sha1-vVjsARzYLe9KcU5AOO9Lc7hBe8M=
30903078
dependencies:
3091-
zrender "4.3.2"
3079+
tslib "2.3.0"
3080+
zrender "5.2.1"
30923081

30933082
ee-first@1.1.1:
30943083
version "1.1.1"
@@ -8937,6 +8926,11 @@ trough@^1.0.0:
89378926
dependencies:
89388927
glob "^7.1.2"
89398928

8929+
tslib@2.3.0:
8930+
version "2.3.0"
8931+
resolved "https://registry.nlark.com/tslib/download/tslib-2.3.0.tgz?cache=0&sync_timestamp=1628722556410&other_urls=https%3A%2F%2Fregistry.nlark.com%2Ftslib%2Fdownload%2Ftslib-2.3.0.tgz#803b8cdab3e12ba581a4ca41c8839bbb0dacb09e"
8932+
integrity sha1-gDuM2rPhK6WBpMpByIObuw2ssJ4=
8933+
89408934
tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0:
89418935
version "1.14.1"
89428936
resolved "https://registry.npm.taobao.org/tslib/download/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
@@ -9728,10 +9722,12 @@ yocto-queue@^0.1.0:
97289722
resolved "https://registry.npm.taobao.org/yocto-queue/download/yocto-queue-0.1.0.tgz?cache=0&sync_timestamp=1606290469373&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fyocto-queue%2Fdownload%2Fyocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
97299723
integrity sha1-ApTrPe4FAo0x7hpfosVWpqrxChs=
97309724

9731-
zrender@4.3.2:
9732-
version "4.3.2"
9733-
resolved "https://registry.npm.taobao.org/zrender/download/zrender-4.3.2.tgz?cache=0&sync_timestamp=1605884245353&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fzrender%2Fdownload%2Fzrender-4.3.2.tgz#ec7432f9415c82c73584b6b7b8c47e1b016209c6"
9734-
integrity sha1-7HQy+UFcgsc1hLa3uMR+GwFiCcY=
9725+
zrender@5.2.1:
9726+
version "5.2.1"
9727+
resolved "https://registry.nlark.com/zrender/download/zrender-5.2.1.tgz#5f4bbda915ba6d412b0b19dc2431beaad05417bb"
9728+
integrity sha1-X0u9qRW6bUErCxncJDG+qtBUF7s=
9729+
dependencies:
9730+
tslib "2.3.0"
97359731

97369732
zwitch@^1.0.0:
97379733
version "1.0.5"

0 commit comments

Comments
 (0)