Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在图表中设置工具提示编号的格式_Javascript_Highcharts - Fatal编程技术网

Javascript 在图表中设置工具提示编号的格式

Javascript 在图表中设置工具提示编号的格式,javascript,highcharts,Javascript,Highcharts,我使用tooltip.pointFormat在工具提示中呈现其他数据。不幸的是,只有point.x的格式使用了千位分隔符 $(函数(){ Highcharts.setOptions({ 全球:{ useUTC:false, }, 朗:{ 小数点:',', 千塞普:'.' } }); $(“#容器”)。高图({ xAxis:{ 键入:“日期时间” }, 工具提示:{ pointFormat:'{series.name}:{point.y}'+'计数:{point.Count}', 分享:真的 }

我使用
tooltip.pointFormat
在工具提示中呈现其他数据。不幸的是,只有
point.x
的格式使用了千位分隔符

$(函数(){
Highcharts.setOptions({
全球:{
useUTC:false,
},
朗:{
小数点:',',
千塞普:'.'
}
});
$(“#容器”)。高图({
xAxis:{
键入:“日期时间”
},
工具提示:{
pointFormat:'{series.name}:{point.y}
'+'计数:{point.Count}
', 分享:真的 }, 系列:[{ 数据:[{ y:20009.9, 计数:20009.9 }, { y:10009.9, 计数:20009.9 }, { y:40009.9, 计数:20009.9 }], pointStart:Date.UTC(2010,0,1), 点间隔:3600*1000//1小时 }] }); });
安装pointFormat时,使用,然后

工具提示:{
格式化程序:函数(){
返回this.point.series.name+':'+Highcharts.numberFormat(this.point.options.count,1',',')+'
'+'计数:'+Highcharts.numberFormat(this.point.y,1',',')+'
'; } },
示例:

找到了答案

数字使用浮点格式约定的子集进行格式设置 从C库函数sprintf。格式将附加在内部 变量括号,用冒号分隔。例如:

  • 小数点后两位:“
    {point.y:.2f}
  • 千位分隔符,无小数点:
    {point.y:,.0f}
  • 千位分隔符,小数点后一位:
    {point.y:,.1f}
因此,在括号内使用
:,.1f
将正确设置数字格式

tooltip: {
  pointFormat: '{series.name}: <b>{point.y}</b><br/>' + 'Count: <b>{point.count:,.1f}</b><br/>',
  shared: true
}
工具提示:{
pointFormat:{series.name}:{point.y}
'+'计数:{point.Count:,.1f}
', 分享:真的 }

在我们的例子中,仅对
y
属性应用格式,我找到了几种方法,不仅为
y
添加格式

  • 为每个工具提示和每个属性添加格式,如
    point.count:,.f

    pointFormat: '{series.name}: <b>{point.count:,.f}</b><br/>' + 'Count: <b>{point.y}</b><br/>',
    

  • 你是故意使用点作为千分之一点吗?是的,因为我在德国。有没有办法将千分格式显示为单值(,)和两个小数点。我以前知道这一点,并试图避免这一点,因为我必须为整组图表支持德语和英语格式。因此,为所有图表设置一次格式比为每个图表设置格式方便得多。另外,标题中的格式化日期现在丢失了。请注意,只有在我像在JSFIDLE中那样指定Highcharts lang decimalPoint和MillandSSEP值时,这才适用于我。
    tooltip: {
      pointFormat: '{series.name}: <b>{point.y}</b><br/>' + 'Count: <b>{point.count:,.1f}</b><br/>',
      shared: true
    }
    
    pointFormat: '{series.name}: <b>{point.count:,.f}</b><br/>' + 'Count: <b>{point.y}</b><br/>',
    
    (function (Highcharts) {
      var tooltipFormatter = Highcharts.Point.prototype.tooltipFormatter;
    
      Highcharts.Point.prototype.tooltipFormatter = function (pointFormat) {
        var keys = this.options && Object.keys(this.options),
            pointArrayMap = this.series.pointArrayMap,
            tooltip;
    
        if (keys.length) {
          this.series.pointArrayMap = keys;
        }     
    
        tooltip = tooltipFormatter.call(this, pointFormat);        
        this.series.pointArrayMap = pointArrayMap || ['y'];
    
        return tooltip;
      }
    }(Highcharts));