是否可以在折线图的数据标签上显示我自己的文本,仅适用于非零条目。假设要在数据标签中显示的文本与数据一起从 xml 传递。
我需要如下图所示的图表。请提出一个想法。谢谢你的时间。
高图表:
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
plotOptions: {
series: {
dataLabels: {
enabled: true,
formatter: function () {
if (this.point.y != 0) {
return this.point.y;
}
},
borderRadius: 5,
backgroundColor: 'pink',
borderWidth: 1,
borderColor: 'green',
y: -6
}
}
},
series: [{
data: [0, 0,77,120,0,0,150,0,0,0,0]
}]
}
Run Code Online (Sandbox Code Playgroud)
XML:
<categories>
<month>Jan</month>
<month>Feb</month>
<month>Mar</month>
<month>Apr</month>
<month>May</month>
<month>Jun</month>
<month>Jul</month>
<month>Aug</month>
<month>Sep</month>
<month>Oct</month>
<month>Nov</month>
<month>Dec</month>
</categories>
<Series>
<point>0|0</point>
<point>0|0</point>
<point>120|First</point>
<point>130|0</point>
<point>0|0</point>
<point>0|0</point>
<point>0|0</point>
<point>150|Second</point>
<point>230|Third</point>
<point>0|0</point>
<point>0|0</point>
<point>0|0</point>
</Series>
Run Code Online (Sandbox Code Playgroud)
jQuery:
$xml.find('series').each(
function(i,series){
var ser = {
data : [],
};
$(series).find('point').each(
function(i,point){
ser.data.push(parseInt($(point).text().split("|")[0]);
});
options.series.push(ser);
});
Run Code Online (Sandbox Code Playgroud)
您可以为每个点添加额外的参数(文本),该参数是在数据标签格式化程序中提取的。如果数据标签不应打印 0 值,请添加检查条件。
plotOptions: {
series: {
dataLabels: {
enabled:true,
formatter: function() {
if(this.y > 0)
return this.point.label;
}
}
}
},
series: [{
data: [{
y: 2,
label: 'text1'
}, {
y: 3,
label: 'text2'
}, {
y: 0
}, {
y: 4,
label: 'text3'
}]
}]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4251 次 |
| 最近记录: |