想要对高图表工具提示结果进行排序
我的 highcharts 工具提示中有 4 个结果,它们没有排序,它们看起来像这样:
somerhing: 10 $
something: 18 $
something: 2 $
something: 8 $
我想将它们从最低 $ 到最高 $ 从 2 $ 到 18 $ 排序,如下所示:
somerhing: 2 $
something: 8 $
something: 10 $
something: 18 $
这是工具提示结果的 highcharts 循环:
tooltip: {
formatter: function() {
var s = '<strong>something: '+ this.x +'</strong>';
$.each(this.points, function(i, point) {
s += '<br/>'+ point.series.name +': '+ point.y +currency;
});
return s;
},
任何想法如何要排序吗?
谢谢。
I have 4 results inside my highcharts tooltip and they are not sorted they looks like this:
somerhing: 10 $
something: 18 $
something: 2 $
something: 8 $
I want to sort them from lowest $ to highest $ from 2$ to 18$ like this:
somerhing: 2 $
something: 8 $
something: 10 $
something: 18 $
Here is the highcharts loop for tooltip results:
tooltip: {
formatter: function() {
var s = '<strong>something: '+ this.x +'</strong>';
$.each(this.points, function(i, point) {
s += '<br/>'+ point.series.name +': '+ point.y +currency;
});
return s;
},
Any ideas how to sort it ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
补充一下上面的答案。
我也想拥有工具提示的默认格式。所以我在 格式化程序中调用了
tooltip.defaultFormatter.call(this, tooltip)
回调。请注意,它是按降序排列的。如果您想要升序,只需删除
items.reverse()
即可。HighCharts v4.0.4
JSFiddle
HighCharts v3.0.2
基于defaultFormatter 函数,将上述内容应用于它。
Adding on to the above answer.
I wanted to have the default formatting of the tooltip as well. So I called
tooltip.defaultFormatter.call(this, tooltip)
inside the formatter callback.Note that it is sorted in descending order. Just remove the
items.reverse()
if you want ascending order.HighCharts v4.0.4
JSFiddle
HighCharts v3.0.2
Based on the defaultFormatter function with the above applied to it.
试试这个
Try this