lineChart.vue
5.41 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<template>
<div>
<basic ref="basic" :chartId="chartId" :chartData="chartData"></basic>
</div>
</template>
<script>
import mixin from './mixin';
export default {
mixins: [mixin],
data() {
return {
}
},
methods: {
/**
* 预处理option参数
* */
preChartData(cdata) {
return cdata;
},
/**
* 处理option参数
* */
dealChartData(optionFormat) {
// 特殊配置项
let {
normalXAxisLabel,
grid,
_color,
hasYaxisName,
yAxisLineHide,
legendBottom,
seriesText,
yAxisName,
isCylindrical,
tooltipTitle,
usePercent = false,
legendShow = false,
legendSelected={},
legendObj,
barWidth
} = optionFormat.otherConf;
let currentClickIndex = null
optionFormat.legend.bottom = legendBottom || 0;
optionFormat.legend.selected = legendSelected;
//optionFormat.legend.itemGap = 65;
optionFormat.legend.show = legendShow;
optionFormat.legend = legendObj||optionFormat.legend;
/*if(optionFormat.series.length==1)*/optionFormat.color = _color;
let areaColor = _color.map(item => {
return {
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [{
offset: 0,
color: item // 0% 处的颜色
},
{
offset: 1,
color: "#fff" // 100% 处的颜色
}
]
};
});
optionFormat.grid = grid || { top: yAxisName?40:20, right: hasYaxisName?40:0, bottom: legendShow?60:20, left: 60 };
optionFormat.tooltip.trigger = "axis";
optionFormat.tooltip.axisPointer = {
type: "line",
lineStyle: {
color: "#444"
}
};
let yAxis = {
type: "value",
name:yAxisName||'',
// nameRotate: 1,
splitLine: {
lineStyle: {
color: "#f5f5f5"
}
},
axisLine: {
show:!yAxisLineHide,
lineStyle: {
color: "#888"
}
},
axisTick: {
show: false
},
axisLabel: {
fontSize: 12,
fontFamily: this.fontFamily,
color: "#666"
}
};
if(hasYaxisName){
yAxis.name = yAxisName[0];
let yAxis2 = Object.assign({},yAxis,{name:yAxisName[1],position:'right'})
optionFormat.yAxis = [yAxis,yAxis2];
}else{
optionFormat.yAxis = yAxis;
}
optionFormat.xAxis.boundaryGap = true;
optionFormat.series.forEach((item,index) => {
if (item.type === "line") {
if(hasYaxisName)item.yAxisIndex = 0;
item.symbol = 'circle';
item.smooth = true;
item.symbolSize = 4;
item.emphasis = {
scale:true
}
item.areaStyle = {
normal: {
color: areaColor[index]
}
};
} else if (item.type === "bar") {
if(hasYaxisName)item.yAxisIndex = 1;
/*item.itemStyle = {
normal: {
color: (params) => {
let key = params.dataIndex
return key === currentClickIndex ? '#0069FF' : '#3BB8FF'
}
}
}*/
if(barWidth&& optionFormat.series.length==1)item.barWidth = barWidth;
// if (isCylindrical) {
// item.barWidth = 14;
//item.barGap = "100%";
// }
}
});
let option = Object.assign({}, optionFormat);
let that = this;
option.series.forEach(item => {
if (item.type === "line" && item.name === "growthRate") {
item.name = this.$t("echarts.growthRate");
} else if (item.type === "bar") {
item.name =
item.name === "avgWeekDay"
? this.$t("echarts.workdayAverageInnum")
: item.name === "avgWeekend"
? this.$t("echarts.weekendAverageInnum")
: item.name;
}
});
if (isCylindrical) {
option.legend.data = option.series.map(item => item.name);
}
option.tooltip.formatter = params => {
let htmls = "";
htmls += `<div style="font-size:14px;height:31px;color:#333;border-radius:4px;line-height:31px;padding-left:15px;padding-right:15px;text-align: left;">${params[0].name}${tooltipTitle || ''}</div><div>`;
params.forEach(item => {
// if (item.seriesName === '去年环比' || item.seriesName === 'Last year ring ratio') {
if (item.componentSubType === "line") {
htmls += `
<p style="font-size:13px;padding:4px 15px;color:#444444; text-align: left;">${
item.marker
} ${item.seriesName}: ${item.data || "--"}${yAxisName||painter.$t('format.perTime')}</p>
`;
} else {
// ${this.$t('format.TRAFFIC')}
htmls += `
<p style="font-size:13px;padding:4px 15px;color:#444444; text-align: left;">
${item.marker} ${item.seriesName}: ${that.toThousands(item.data|| "--")}${this.$t("format.perTime")}
</p>
`;
}
});
htmls += "</div>";
return htmls;
};
return option;
}
},
created() {
}
}
</script>
<style scoped>
.chart {
position: relative;
height: 500px;
}
</style>