1
|
// pages/qiyeyongdian/detail/detail.js
|
1
|
// pages/qiyeyongdian/detail/detail.js
|
|
|
2
|
+
|
|
|
3
|
+import * as echarts from '../../../ec-canvas/echarts';
|
|
|
4
|
+
|
|
|
5
|
+const app = getApp();
|
|
|
6
|
+var Chart = null;
|
2
|
Page({
|
7
|
Page({
|
3
|
|
8
|
|
4
|
/**
|
9
|
/**
|
|
@@ -7,9 +12,31 @@ Page({ |
|
@@ -7,9 +12,31 @@ Page({ |
7
|
data: {
|
12
|
data: {
|
8
|
showModal: false,
|
13
|
showModal: false,
|
9
|
monthList: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
|
14
|
monthList: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
|
10
|
- changeColor:-1,
|
15
|
+ changeColor: -1,
|
|
|
16
|
+ ec: {
|
|
|
17
|
+
|
|
|
18
|
+ onInit: function(canvas, width, height) {
|
|
|
19
|
+
|
|
|
20
|
+ chart = echarts.init(canvas, null, {
|
|
|
21
|
+
|
|
|
22
|
+ width: width,
|
|
|
23
|
+
|
|
|
24
|
+ height: height
|
|
|
25
|
+
|
|
|
26
|
+ });
|
|
|
27
|
+
|
|
|
28
|
+ canvas.setChart(chart);
|
|
|
29
|
+
|
|
|
30
|
+ return chart;
|
|
|
31
|
+
|
|
|
32
|
+ },
|
|
|
33
|
+
|
|
|
34
|
+ lazyLoad: true // 延迟加载
|
|
|
35
|
+
|
|
|
36
|
+ },
|
|
|
37
|
+
|
11
|
},
|
38
|
},
|
12
|
- choice(e){
|
39
|
+ choice(e) {
|
13
|
let index = e.currentTarget.dataset.id;
|
40
|
let index = e.currentTarget.dataset.id;
|
14
|
this.setData({
|
41
|
this.setData({
|
15
|
changeColor: index
|
42
|
changeColor: index
|
|
@@ -32,8 +59,161 @@ Page({ |
|
@@ -32,8 +59,161 @@ Page({ |
32
|
*/
|
59
|
*/
|
33
|
onLoad: function(options) {
|
60
|
onLoad: function(options) {
|
34
|
|
61
|
|
|
|
62
|
+ this.echartsComponnet = this.selectComponent('#mychart');
|
|
|
63
|
+
|
|
|
64
|
+ //如果是第一次绘制
|
|
|
65
|
+
|
|
|
66
|
+ if (!Chart) {
|
|
|
67
|
+
|
|
|
68
|
+ this.init_echarts(); //初始化图表
|
|
|
69
|
+
|
|
|
70
|
+ } else {
|
|
|
71
|
+
|
|
|
72
|
+ this.setOption(Chart); //更新数据
|
|
|
73
|
+
|
|
|
74
|
+ }
|
|
|
75
|
+
|
|
|
76
|
+ },
|
|
|
77
|
+ //初始化图表
|
|
|
78
|
+
|
|
|
79
|
+ init_echarts: function() {
|
|
|
80
|
+
|
|
|
81
|
+ this.echartsComponnet.init((canvas, width, height) => {
|
|
|
82
|
+
|
|
|
83
|
+ // 初始化图表
|
|
|
84
|
+
|
|
|
85
|
+ const Chart = echarts.init(canvas, null, {
|
|
|
86
|
+
|
|
|
87
|
+ width: width,
|
|
|
88
|
+
|
|
|
89
|
+ height: height
|
|
|
90
|
+
|
|
|
91
|
+ });
|
|
|
92
|
+
|
|
|
93
|
+ this.setOption(Chart)
|
|
|
94
|
+
|
|
|
95
|
+ // 注意这里一定要返回 chart 实例,否则会影响事件处理等
|
|
|
96
|
+
|
|
|
97
|
+ return Chart;
|
|
|
98
|
+
|
|
|
99
|
+ });
|
|
|
100
|
+
|
|
|
101
|
+ },
|
|
|
102
|
+
|
|
|
103
|
+ setOption: function(Chart) {
|
|
|
104
|
+
|
|
|
105
|
+ Chart.clear(); // 清除
|
|
|
106
|
+
|
|
|
107
|
+ Chart.setOption(this.getOption()); //获取新数据
|
|
|
108
|
+
|
|
|
109
|
+ },
|
|
|
110
|
+
|
|
|
111
|
+ // 图表配置项
|
|
|
112
|
+
|
|
|
113
|
+ getOption() {
|
|
|
114
|
+
|
|
|
115
|
+ var self = this;
|
|
|
116
|
+
|
|
|
117
|
+ var option = {
|
|
|
118
|
+
|
|
|
119
|
+ color: ["#FFF"], //图例图标颜色
|
|
|
120
|
+ // lineStyle:{//阴影
|
|
|
121
|
+ // shadowColor: '#6495F8',
|
|
|
122
|
+ // shadowBlur: 10
|
|
|
123
|
+ // },
|
|
|
124
|
+ xAxis: { //横坐标
|
|
|
125
|
+
|
|
|
126
|
+ type: 'category',
|
|
|
127
|
+
|
|
|
128
|
+ name: '日期', //横坐标名称
|
|
|
129
|
+
|
|
|
130
|
+ nameTextStyle: { //在name值存在下,设置name的样式
|
|
|
131
|
+
|
|
|
132
|
+ color: '#333',
|
|
|
133
|
+
|
|
|
134
|
+ fontStyle: 'normal'
|
|
|
135
|
+
|
|
|
136
|
+ },
|
|
|
137
|
+ axisLabel: {
|
|
|
138
|
+ interval: 0,
|
|
|
139
|
+ },
|
|
|
140
|
+ boundaryGap: false, //1.true 数据点在2个刻度直接 2.fals 数据点在分割线上,即刻度值上
|
|
|
141
|
+
|
|
|
142
|
+ data: ['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'],
|
|
|
143
|
+
|
|
|
144
|
+ axisLabel: {
|
|
|
145
|
+
|
|
|
146
|
+ textStyle: {
|
|
|
147
|
+
|
|
|
148
|
+ fontSize: 13,
|
|
|
149
|
+
|
|
|
150
|
+ color: '#5D5D5D'
|
|
|
151
|
+
|
|
|
152
|
+ }
|
|
|
153
|
+
|
|
|
154
|
+ }
|
|
|
155
|
+
|
|
|
156
|
+ },
|
|
|
157
|
+
|
|
|
158
|
+ yAxis: { //纵坐标
|
|
|
159
|
+
|
|
|
160
|
+ type: 'value',
|
|
|
161
|
+
|
|
|
162
|
+ position: 'left',
|
|
|
163
|
+
|
|
|
164
|
+ name: '千瓦时', //纵坐标名称
|
|
|
165
|
+
|
|
|
166
|
+ nameTextStyle: { //在name值存在下,设置name的样式
|
|
|
167
|
+
|
|
|
168
|
+ color: '#333333',
|
|
|
169
|
+
|
|
|
170
|
+ fontStyle: 'normal'
|
|
|
171
|
+
|
35
|
},
|
172
|
},
|
36
|
|
173
|
|
|
|
174
|
+ splitNumber: 5, //坐标轴的分割段数
|
|
|
175
|
+
|
|
|
176
|
+
|
|
|
177
|
+ min: 0,
|
|
|
178
|
+
|
|
|
179
|
+ max: 500,
|
|
|
180
|
+
|
|
|
181
|
+ },
|
|
|
182
|
+
|
|
|
183
|
+ series: [{
|
|
|
184
|
+
|
|
|
185
|
+ type: 'line',
|
|
|
186
|
+
|
|
|
187
|
+ data: [100, 120, 123, 142, 231, 231, 123, 341, 234, 432, 100, 120, 123, 142, 231, 231, 123, 341, 234, 432, 100, 120, 123, 142, 231, 231, 123, 341, 234, 432,253],
|
|
|
188
|
+
|
|
|
189
|
+ symbol: 'true',
|
|
|
190
|
+
|
|
|
191
|
+ itemStyle: {
|
|
|
192
|
+
|
|
|
193
|
+ normal: {
|
|
|
194
|
+
|
|
|
195
|
+ lineStyle: {
|
|
|
196
|
+
|
|
|
197
|
+ color: '#6495F8'
|
|
|
198
|
+
|
|
|
199
|
+ }
|
|
|
200
|
+
|
|
|
201
|
+ }
|
|
|
202
|
+
|
|
|
203
|
+ },
|
|
|
204
|
+ // areaStyle: {
|
|
|
205
|
+ // normal: {
|
|
|
206
|
+ // color: '#6495F8' //改变区域颜色
|
|
|
207
|
+ // }
|
|
|
208
|
+ // },
|
|
|
209
|
+
|
|
|
210
|
+ }],
|
|
|
211
|
+
|
|
|
212
|
+ }
|
|
|
213
|
+
|
|
|
214
|
+ return option;
|
|
|
215
|
+
|
|
|
216
|
+ },
|
37
|
/**
|
217
|
/**
|
38
|
* 生命周期函数--监听页面初次渲染完成
|
218
|
* 生命周期函数--监听页面初次渲染完成
|
39
|
*/
|
219
|
*/
|