[英]Highcharts show plot value on x axis label
I have a spiderweb graph with just the one data series. 我有一个只有一个数据系列的蜘蛛网图。 In the interests of printing I'd like to incorporate the value plotted in the label after the actual label name but I can't seem to work out how to do so. 为了印刷的利益,我想在实际标签名称之后加入标签中绘制的值,但我似乎无法弄清楚如何这样做。
This example to help explain what I mean is a bar-graph that I found in my search. 这个例子有助于解释我的意思是我在搜索中找到的条形图。 The code layout is similar and a lot less cluttered than mine and I'm fairly sure a solution on this one would be easily transferable. 代码布局类似,并且比我的更简洁,我相当确定这个解决方案很容易转移。
labels: {
formatter: function() {
return this.value + ' XX.X';
}
}
So for the X axis I'm trying to replace the "XX.X" with the relevant Y value to get the labels: "Foo 29.9 | Bar 71.5 | Foobar 106.4" 所以对于X轴,我试图用相关的Y值替换“XX.X”来得到标签:“Foo 29.9 | Bar 71.5 | Foobar 106.4”
I dug through "this" in the xAxis labels formatter and got as far as finding the Y figures at "this.chart.series[0].yData", but couldn't work out a way to associate these back to each relevant X label, and I thought it seemed the wrong way of going about things anyway. 我在xAxis标签格式化程序中挖掘了“this”,并在“this.chart.series [0] .yData”中查找了Y数字,但无法找到将这些数据关联回每个相关X的方法标签,我认为这似乎是错误的做事方式。
You can do this after rendering of the chart in the chart.events.load
method using setCategories
. 您可以使用setCategories
在chart.events.load
方法中渲染图表后执行此setCategories
。 This code below assumes that each index element on the xAxis has a corresponding data element. 下面的代码假定xAxis上的每个索引元素都有一个对应的数据元素。 If it doesn't then you would need to handle that case. 如果没有,那么你需要处理这种情况。
chart: {
events: {
load: function (event) {
var cats = this.xAxis[0].categories;
var theData = this.series[0].data;
var newCats = [];
for (var i = 0; i < cats.length; i++) {
newCats.push(cats[i] + ' ' + theData[i].y)
}
this.xAxis[0].setCategories(newCats);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.