当超过100或1000时,Highcharts在工具提示上添加符号 [英] Highcharts add symbol on tooltip when over 100 or 1000

查看:128
本文介绍了当超过100或1000时,Highcharts在工具提示上添加符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在工具栏上显示工具提示时,在工具栏上有一个符号,但它也有共享:true。同样在图表中,当它是2394时,我将它缩小到2.39,所以图形不是那么大,然后在工具栏上显示2.39K。



我已经尝试了很多,我无法弄清楚所有的堆栈溢出,没有发现任何东西。

http://jsfiddle.net/sb7n32zn/22/



是我现在有的:

 工具提示:{
shared:true,
pointFormat:'< span style =color:{series.color}> {series.name}:< b> {point.y:,2f}< / b>< br />',



解决方案

您需要使用工具提示.format其中并检测值> 1000.然后使用 Highcharts.numberFormat 并转换编号。

  formatter:function() {
var points = this.points,
each = Highcharts.each,
txt ='< span style =font-size:10px>'+ points [0]。 key +'< / span>< br />',
H = Highcharts,
值,
numericSymbolDetector;

each(points,function(point,i){
value = point.y;
numericSymbolDetector = Math.abs(point.y);
if( numericSymbolDetector> 1000){
value = H.numberFormat(value / 1000,2,'。','')+'k';
}
txt + ='});

return txt;

$ / code>

示例:


I am trying to make the tooltip when it is 100 + and 1000 + Have a symbol after it on the toolbar but also have it so that shared: true. Also on the graph when it is say 2394 I am after it to round it down to 2.39 so the graph is not so large and then on the tool bar it would show 2.39K.

I have tried quite a bit and I am not able to figure this out look all over stack overflow and not found anything.

http://jsfiddle.net/sb7n32zn/22/

This is what i currently have:

tooltip: {
    shared: true,
    pointFormat: '<span style="color:{series.color}">{series.name}: <b>{point.y:,.2f}</b><br/>',

}

解决方案

You need to use a tooltip.formatter which and detect values > 1000. Then use Highcharts.numberFormat and convert number.

formatter: function() {
    var points = this.points,
      each = Highcharts.each,
      txt = '<span style="font-size: 10px">' + points[0].key + '</span><br/>',
      H = Highcharts,
      value,
      numericSymbolDetector;

    each(points, function(point, i) {
      value = point.y;
      numericSymbolDetector = Math.abs(point.y);
      if (numericSymbolDetector > 1000) {
         value = H.numberFormat(value / 1000, 2, '.','' ) + 'k';
      } 
      txt += '<span style="color:' + point.series.color + '">' + point.series.name + ': <b>' + value + '</b><br/>';
    });

    return txt;
  }

Example:

这篇关于当超过100或1000时,Highcharts在工具提示上添加符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆