Skip to content

Commit 6c58f91

Browse files
committed
distribution chart
1 parent 762dea2 commit 6c58f91

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
lines changed

src/pages/lottery/ballChart.tsx

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ 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'
5+
import * as Echart from 'echarts/lib/echarts'
66
// const Echart = require('echarts/lib/echarts')
77
// 引入柱状图
88
require('echarts/lib/chart/bar');
9+
require('echarts/lib/chart/line');
910
// 引入提示框和标题组件
1011
require('echarts/lib/component/tooltip');
1112
require('echarts/lib/component/title');
@@ -16,8 +17,10 @@ export default class BallChart extends React.Component<IProps> {
1617

1718
chartRef: any = React.createRef()
1819
blueRef: any = React.createRef()
20+
redChartRef: any = React.createRef()
1921
ballCountChart: Echart.ECharts
2022
blueBallCountChart: Echart.ECharts
23+
redBallDistributionChart: Echart.ECharts
2124

2225
state = {
2326
visible: false
@@ -46,12 +49,26 @@ export default class BallChart extends React.Component<IProps> {
4649
componentDidMount() {
4750
this.ballCountChart = Echart.init(this.chartRef.current)
4851
this.blueBallCountChart = Echart.init(this.blueRef.current)
52+
this.redBallDistributionChart = Echart.init(this.redChartRef.current)
53+
4954
const { fetchChartData } = this.props.ballChartStore
5055

51-
fetchChartData((reds:[any], blues:[any]) => {
56+
fetchChartData((reds:[any], blues:[any], redDisList:[[any]]) => {
57+
const series: any = redDisList.map((item, i) => {
58+
return {
59+
name: `红球${i + 1}`,
60+
type: 'line',
61+
smooth: true,
62+
showSymbol: false,
63+
symbol: 'circle',
64+
symbolSize: 6,
65+
data: item.map(v => v.value)
66+
}
67+
})
68+
5269
this.ballCountChart.setOption({
5370
title: {
54-
text: '红球'
71+
text: '红球'
5572
},
5673
tooltip: {},
5774
grid: {
@@ -61,13 +78,13 @@ export default class BallChart extends React.Component<IProps> {
6178
containLabel: true
6279
},
6380
xAxis: {
64-
data: reds.map(v => v.name)
81+
data: reds.map(v => v.name)
6582
},
6683
yAxis: {},
6784
series: [{
68-
name: '次数',
69-
type: 'bar',
70-
data: reds.map(v => v.value)
85+
name: '次数',
86+
type: 'bar',
87+
data: reds.map(v => v.value)
7188
}],
7289
color: ['#f54646']
7390
})
@@ -84,16 +101,36 @@ export default class BallChart extends React.Component<IProps> {
84101
containLabel: true
85102
},
86103
xAxis: {
87-
data: blues.map(v => v.name)
104+
data: blues.map(v => v.name)
88105
},
89106
yAxis: {},
90107
series: [{
91-
name: '次数',
92-
type: 'bar',
93-
data: blues.map(v => v.value)
108+
name: '次数',
109+
type: 'bar',
110+
data: blues.map(v => v.value)
94111
}],
95112
color: ['#3399ff']
96113
})
114+
115+
this.redBallDistributionChart.setOption({
116+
title: {
117+
text: '红球分布图'
118+
},
119+
tooltip: {},
120+
grid: {
121+
left: '2%',
122+
right: '2%',
123+
bottom: '3%',
124+
containLabel: true
125+
},
126+
xAxis: {
127+
data: reds.map(v => v.name)
128+
},
129+
yAxis: {},
130+
series: series,
131+
// color: ['#f54646','#f5464685','#f5464670','#f5464655','#f5464640','#f5464625']
132+
color: ['#f54646','#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3']
133+
})
97134
})
98135
}
99136

@@ -109,6 +146,12 @@ export default class BallChart extends React.Component<IProps> {
109146
<div className='chart-w' ref={this.blueRef}></div>
110147
</Col>
111148
</Row>
149+
<h3>红球历史出现分布图</h3>
150+
<Row>
151+
<Col span={24}>
152+
<div className='chart-w' style={{borderRight: 'none'}} ref={this.redChartRef}></div>
153+
</Col>
154+
</Row>
112155
</div>
113156
</React.Fragment>
114157

src/pages/lottery/ballChartStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { GRAPHQL_API } from '@constants/index';
44
const queryChart = `
55
fragment common on ballChartType { name value }
66
query ball{
7-
ballCount{reds{...common},blues{...common}}
7+
ballCount{reds{...common},blues{...common},redDisList{...common}}
88
}`
99

1010

@@ -38,7 +38,7 @@ class ballChartStore {
3838
// this.reds = ballCount.reds
3939
// this.blues = ballCount.blues
4040
// console.log(ballCount)
41-
cb && cb(ballCount.reds, ballCount.blues)
41+
cb && cb(ballCount.reds, ballCount.blues, ballCount.redDisList)
4242
})
4343
}, err => {
4444
runInAction(() => {

0 commit comments

Comments
 (0)