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
|
function(options) {
var avgValue = parseFloat("&P222_AVG."); // 从页面项获取平均值
options.dataFilter = function(data) {
// 设置原始系列颜色
data.series[0].color = "rgb(21, 159, 237)";
// 创建与原始数据等长的平均值数组
var itemCount = data.series[0].items.length;
var avgArray = Array(itemCount).fill(avgValue);
// 添加平均线 series
data.series.push({
name: "平均"+(avgValue*100)+'%',
items: avgArray,
type: "line",
color: "rgb(252, 220, 115)",
lineWidth: 4,
lineStyle: "solid",
markerDisplayed: "off" // 关闭标记点,视觉更干净
});
return data;
};
// 全局样式:启用数据标签,并通过 renderer 精准控制
options.styleDefaults = {
dataLabel: {
display: "on", // 开启标签显示
textType: "value", // 显示实际数值
hAlign: "center", // 水平居中
vAlign: "above", // 显示在上方
tickLabel: {
show: true,
position: 'end', // 可选 'insideTop', 'outside' 等
rendered: 'on',
},
style: {
fill: "rgb(252, 220, 115)", // 标签颜色
"font-weight": "bold",
"font-size": "12px"
},
renderer: function(context) {
// 仅对最后一个 series(即平均线)显示标签
if (context.seriesIndex === context.componentOptions.series.length - 1) {
return avgValue.toFixed(2); // 显示固定两位小数的平均值
}
return null; // 其他系列不显示标签
}
}
};
// 必须使用 combo 类型以混合 bar 和 line
options.type = "combo";
return options;
}
|