在Highcharts中添加标签 [英] Add label to line in Highcharts
问题描述
我很努力在highcharts的一行顶部添加标签..例如,假设我有4个系列(全部可见),名称'data'
,'mean'
,'+ 1 std'
,' - 1 std'
:
我想结果是:
我迷路了如何添加它...即使有文档,我似乎需要为每个标签添加横坐标和纵坐标。我如何检索这些信息?是否可以在添加系列时直接添加标签?
chart.addSeries({
id:'意思',
名称:'mean',
类型:'line',
lineWidth:1,
lineColor:'rgba(0,128,0,0.9)',
color:'rgba(0,128,0,0.9)',
dashStyle:'LongDash',
zIndex:5,
data:[[ext.dataMin,mean],[ext .dataMax,mean]],
enableMouseTracking:false
});
请注意,我 不希望 将这些信息显示在图例中,但在图表本身 -
您可以使用 dataLabel
。
如果在plotOptions中禁用dataLabels,但在每个系列的第一个点上启用它们,
代码示例:
data:[
{
x:0,
y:5,
dataLabels:{
enabled:true,
format:'label 1:{y}'
}
},
[10,5]
]
小提琴示例:
I struggle to add a label on top of a line in highcharts .. for example suppose I have 4 series (all visible) with name 'data'
, 'mean'
, '+1 std'
, '-1 std'
:
And I would like as a result:
I am lost to know how to add it ... even with the documentation it seems I need the abscissa and ordinate to add for each label. How can I retrieve this information? Is it possible to add the label directly when I add the series?
chart.addSeries({
id : 'mean',
name : 'mean',
type : 'line',
lineWidth : 1,
lineColor : 'rgba(0,128,0,0.9)',
color : 'rgba(0,128,0,0.9)',
dashStyle : 'LongDash',
zIndex : 5,
data : [[ext.dataMin, mean], [ext.dataMax, mean]],
enableMouseTracking: false
});
Notice that I do not want to display this information in a legend, but on the chart itself-
You can do this with a dataLabel
.
If you disable dataLabels in the plotOptions, but enable them on the first point of each series, you will get exactly what you're asking for.
Code example:
data: [
{
x:0,
y:5,
dataLabels:{
enabled: true,
format: 'label 1: {y}'
}
},
[10,5]
]
Fiddle example:
这篇关于在Highcharts中添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!