回首憶惘然
2021-11-12 14:20:32
我想訪問系列 dataLabels 中的另一個系列行數(shù)據(jù)。這是我的代碼。categoriesarr = [1,2,3,4,5];noofloandisbursed = [10, 20, 30, 40, 50];pdo = [9, 18, 27, 40, 49];var chart = new Highcharts.Chart({ chart: { renderTo: 'disbursement' }, title: { text: '' }, subtitle: { text: '' }, xAxis: { categories: categoriesarr }, tooltip: { pointFormat: '<b>{point.y}</b>' }, legend: { layout: 'vertical', align: 'right', verticalAlign: 'top', x: -40, y: 0, floating: true, borderWidth: 1, backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#fff'), shadow: true }, series: [{ name: 'No. Of Loan Disbursed', type: 'column', data: noofloandisbursed }, { name: 'Pre-Disbursement Orientation', type: 'column', data: pdo, dataLabels: { enabled: true, formatter: function(e) { //return ((this.point.y/series[0].point.y)*100) + '%'; } } }] });我想在 dataLabels 連接中顯示 (series 2 value / series 1 value) * 100 的結果,僅在第二個系列中使用 % 。不幸的是,我無法訪問系列 1 的 y 點值。當我嘗試時series[0].yData,它返回整個數(shù)組,而不是與第二行匹配的特定行。我也嘗試傳遞數(shù)組,但它不起作用。需要解決這個問題。
1 回答

慕的地10843
TA貢獻1785條經(jīng)驗 獲得超8個贊
您可以通過index以下方式從第一個系列中找到要點:
series: [{
...
},
{
...,
dataLabels: {
enabled: true,
formatter: function(e) {
return (
(this.point.y /
this.series.chart.series[0].points[this.point.index].y) *
100) + '%';
}
}
}
]
現(xiàn)場演示: http : //jsfiddle.net/BlackLabel/rdwxc382/
API參考: https : //api.highcharts.com/highcharts/series.column.dataLabels.formatter
添加回答
舉報
0/150
提交
取消