echart.js
5.57 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import * as echarts from '../ec-canvas/echarts'
Component({
/**
* 组件的属性列表
*/
properties: {
chartData: {
type: Object,
value: {}
}
},
observers: {
'chartData.data': function (data) {
console.log(data, 'pie----------------')
data && this.onInitChart(data)
}
},
/**
* 组件的初始数据
*/
data: {
ec: {
// lazyLoad: false
lazyLoad: true
},
allList: false
},
attached() {
let { chartData } = this.data
console.log(chartData, 'chartDataattached')
chartData && chartData.data && this.onInitChart()
},
/**
* 组件的方法列表
*/
methods: {
showAll() {
this.setData({
allList: !this.data.allList
})
},
onInitChart() {
// console.log(this.ecComponent, this.selectComponent('#mychart-dom-bar'), 'this.ecComponent')
let ecComponent = this.ecComponent || this.selectComponent('#mychart-dom-bar')
ecComponent &&
ecComponent.init((canvas, width, height, dpr) => {
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr
})
this.setOption(chart)
return chart
})
},
setOption(chart) {
let { chartData } = this.data
// const abscissaDataList = [],
// orderMoneyTotalList = [],
// upgradeAveragePriceList = [],
// upgradeRateList = []
// diagramList.forEach(element => {
// abscissaDataList.push(element.abscissaData)
// orderMoneyTotalList.push(this.sceneId == 0 ? element.orderMoneyTotal : element.outputValue)
// upgradeAveragePriceList.push(this.sceneId == 0 ? element.upgradeAveragePrice : element.avgPrice)
// upgradeRateList.push(element.upgradeRate || 0)
// })
// const colors = ['#3582EE', '#35C376', '#FF9D0A']
var option = {
title: {
show: true, //显示策略,默认值true,可选为:true(显示) | false(隐藏)
text: chartData.total + '人', //主标题文本,'\n'指定换行
x: 'center', //水平安放位置,默认为'left',可选为:'center' | 'left' | 'right' | {number}(x坐标,单位px)
y: 'center', //垂直安放位置,默认为top,可选为:'top' | 'bottom' | 'center' | {number}(y坐标,单位px)
textAlign: null, //水平对齐方式,默认根据x设置自动调整,可选为: left' | 'right' | 'center
padding: 5, //标题内边距,单位px,默认各方向内边距为5,接受数组分别设定上右下左边距
// itemGap: 10, //主副标题纵向间隔,单位px,默认为10
textStyle: {
//主标题文本样式{"fontSize": 18,"fontWeight": "bolder","color": "#333"}
fontFamily: 'PingFangSC-Medium, Verdana, sans...',
fontSize: 14,
fontStyle: 'normal',
color: '#333333',
fontWeight: '600'
},
zlevel: 0, //一级层叠控制。默认0,每一个不同的zlevel将产生一个独立的canvas,相同zlevel的组件或图标将在同一个canvas上渲染。zlevel越高越靠顶层,canvas对象增多会消耗更多的内存和性能,并不建议设置过多的zlevel,大部分情况可以通过二级层叠控制z实现层叠控制。
z: 6 //二级层叠控制,默认6,同一个canvas(相同zlevel)上z越高约靠顶层。
},
color: ['#5fcf90','#ffb13c', '#f56c51', '#5f9cf3', ],
tooltip: {
trigger: 'item'
},
label: {
show: true,
formatter: '{b}\n{c}',
// alignTo: 'labelLine',
align: 'right',
edgeDistance: '10%' // 可以调整文字与饼图边缘的距离
// rich: {
// // d: {
// // color: '#fff',
// // fontSize: 16,
// // lineHeight: 24,
// // height: 24
// // },
// align: {
// // color: '#5fcf90',
// fontSize: 14,
// // lineHeight: 20,
// align: 'right'
// }
// }
// textStyle: {
// color: '#fff',
// align: 'right',
// fontSize: 14
// }
},
series: [
{
type: 'pie',
radius: ['40%', '70%'],
minAngle: 10,
labelLine: {
//设置提示线的长度
normal: {
length: 10, //第一条线
length2: 15 //第二条线
}
},
emphasis: {
label: {
show: true,
fontSize: 14,
// fontWeight: 'bold'
}
},
data: chartData.data
// [
// { value: 1048, name: '已预约' },
// { value: 735, name: '取消预约' },
// { value: 580, name: '超时未到店' },
// { value: 484, name: '待预约' }
// ]
}
]
}
chart.setOption(option)
},
//初始化数据
initData(data) {
// const xData = [],
// yData = []
// const [x, y] = this.data.keys
// data.forEach(item => {
// xData.push(item[x])
// yData.push(item[y])
// })
// this.setData({
// xData,
// yData
// })
// this.onInitChart(xData, yData)
}
},
ready() {
// 获取组件
this.ecComponent = this.selectComponent('#mychart-dom-bar')
}
})