loadCurveEchart.ts
2.92 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
import * as echarts from './../../ec-canvas/echarts';
function initChart(canvas: any, width: any, height: any, data: any, dpr: any) {
console.log(data, 'data-------data')
const chart = echarts.init(canvas, null, {
width: width,
height: height,
devicePixelRatio: dpr // new
});
canvas.setChart(chart);
var color = ["#165DFF", "#14C9C9"]
var option = {
legend: {
// data: ['预算', '实际'],//legend
top: 20,
right: 20,
icon: "rect",
textStyle: {
fontSize: 12,
color: '#323241',
},
itemHeight: 4,
itemWidth: 16
},
grid: {
containLabel: true,
bottom: "10",
left:"10",
right:"10"
},
color: color,
tooltip: {
show: true,
trigger: 'axis'
},
xAxis: {
type: 'category',
boundaryGap: true,//不从0开始
axisLine: {//不显示
show: false
},
axisLabel: {
show: true, // x轴文字是否显示,刻度值
textStyle: {
color: '#999999', // 文本颜色
fontSize: 10 // 文本字体大小
},
},
axisTick: {
show: false,
alignWithLabel: true
},
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
// show: false
},
yAxis: {
x: 'center',
type: 'value',
name: "单位(kWh)",//name
splitNumber: 3,
nameTextStyle: {//y轴名字样式
color: "#999999",
fontSize: "10",
padding: [0, 0, 0, 40]
},
axisLabel: {
show: true, // y轴文字是否显示,刻度值
textStyle: {
color: '#999999', // 文本颜色
fontSize: 10 // 文本字体大小
},
},
splitLine: {//y轴刻度线
lineStyle: {
type: 'dashed'
}
}
// show: false
},
series: getSeriesData(data, color)
};
chart.setOption(option);
return chart;
}
let seriesList: any = []
const getSeriesData = (data: any, color: Array<String>) => {
seriesList = []
for (let i = 0; i < data.nameList.length; i++) {
const name = data.nameList[i];
const list = data.dataList[i]
let baseConfig = {
name: name,
type: 'line',
smooth: true,
symbol: "none",
lineStyle: {
width: 1
},
areaStyle: {
opacity: 0.2,
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: color[i]
},
{
offset: 1,
color: color[i]
}
])
},
data: list
}
seriesList.push(baseConfig)
}
return seriesList
}
Component({
/**
* 组件的属性列表
*/
properties: {
echartData: {
type: Object,
value: () => { }
}
},
/**
* 组件的初始数据
*/
data: {
ec: {
onInit: initChart
}
}
/**
* 组件的方法列表
*/
})