Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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
有了HighCharts,我怎么能拥有与y轴相同的工具提示格式化程序_Highcharts - Fatal编程技术网

有了HighCharts,我怎么能拥有与y轴相同的工具提示格式化程序

有了HighCharts,我怎么能拥有与y轴相同的工具提示格式化程序,highcharts,Highcharts,对于HighCharts,我的工具提示格式化程序是否可以使用选定的y轴格式化程序?在本文中,我添加了一个y轴格式化程序(除以千),但工具提示内容仍然未格式化 编辑:我有一个y轴和系列的动态编号 .highcharts({ tooltip: { borderWidth: 1, borderColor: '#AAA', formatter: function(e){ // do some magic here } },

对于HighCharts,我的工具提示格式化程序是否可以使用选定的y轴格式化程序?在本文中,我添加了一个y轴格式化程序(除以千),但工具提示内容仍然未格式化

编辑:我有一个y轴和系列的动态编号

.highcharts({
    tooltip: {
      borderWidth: 1,
      borderColor: '#AAA',
      formatter: function(e){
         // do some magic here
      }
    },
    yAxis: [
        {
      id: 'score',
        min: 0,
        max: 10000,
        title: 'Score',
        labels: {
            formatter: function(e){
            return e.value/1000 + 'k';
          }
        }
      }
    ],
    series: [{
        type: 'spline',
        name: 'Laurel',
        data: [1000,2000,3000,8000,5000],
        yAxis: 'score'
    },
    {
        type: 'spline',
        name: 'Yanni',
        data: [3000,7000,3000,2000,1000],
        yAxis: 'score'
    }]
});

您必须设置
工具提示格式化程序
,如下所示:

tooltip:{
  ...
  formatter: function(){
    var text = '';
    if(this.series.index == 0) {
        text = this.series.name + ' : ' + this.y/1000 + 'k';
    } else {
        text = '<b>' + this.series.name + '</b> : ' + this.y ;
    }
    return text;
  }
}
工具提示:{
...
格式化程序:函数(){
var text='';
如果(this.series.index==0){
text=this.series.name+':'+this.y/1000+'k';
}否则{
text=''+this.series.name+':''+this.y;
}
返回文本;
}
}


编辑多个y轴

一个y轴可以,但我可能有几个y轴。有没有办法使用实际的y轴格式化程序?如果你只是想用格式化程序格式化工具提示,@Core972已经发布了答案。如果您的问题是是否可以重用或使用相同的格式化程序来创建标签和工具提示,那么答案是否定的。您只能将实际值传递给对其执行相同操作的函数。好的,我还没有完全弄清楚这一点。我可能有多个y轴,每个y轴都有不同的格式-在同一个图表上绘制公里和分钟。从工具提示格式化程序中,我知道该系列的名称。也许可以在那里做一些黑客攻击…你有一些选择。可以为每个系列包含自定义标志,并基于自定义标志设置工具提示/轴的格式。当然,您也可以按名称进行匹配。或者,您也可以为每个系列设置工具提示格式化程序(并使函数可以在许多系列中重用),API:I使用多个
yAxis编辑了我的答案我设法找到了一个好的解决方案。也可以在//this.series.options上找到序列的格式化功能-