[英]Highcharts align data label to x-axis if value is negative
我有一個Highcharts圖,其中啟用了數據標簽。 默認情況下,數據標簽貼在每個數據欄的末尾(請參閱此提琴: http : //jsfiddle.net/cyphun/NHCvW )。
是否可以移動負數據標簽並將其顯示在x軸旁邊而不是橫條的末端? 這是我想做的工作的截圖:
http://cl.ly/image/2G3F0I2l2m1z
這是我的Highcharts示例代碼的副本:
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
plotOptions: {
column: {
dataLabels: {
enabled: true,
useHTML: true,
style: {
color: '#252525',
fontWeight: 'bold'
}
}
}
},
title: {
text: 'Column chart with negative values'
},
xAxis: {
categories: ['Apples', 'Oranges', 'Pears', 'Grapes', 'Bananas']
},
tooltip: {
formatter: function() {
return ''+
this.series.name +': '+ this.y +'';
}
},
credits: {
enabled: false
},
series: [{
name: 'Jane',
data: [2, -2, -3, 2, 1]
}]
});
});
});
謝謝您的幫助!
您可以通過使用stackLabels並通過設置dataLabels的y(位置y)屬性來完成一些技巧。 另外,您應該將dataLabels的verticalAlign設置為“ top”。
plotOptions: {
column: {
dataLabels: {
enabled: true,
useHTML: true,
style: {
color: '#252525',
fontWeight: 'bold'
},
verticalAlign : 'top',
y: -15
}
}
}
演示: http : //jsfiddle.net/NHCvW/49/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.