简体   繁体   English

添加自定义文本工具提示,该提示在Highcharts中各有不同

[英]Add a custom text tooltip that differs from point to point in Highcharts

I am trying to develop a chart that displays a custom 'text' tooltip that I can set to change from point to point. 我正在尝试开发一个显示自定义“文本”工具提示的图表,我可以将其设置为逐点更改。 Here is my code as of now: 到目前为止,这是我的代码:

            tooltip: {
                headerFormat: '<b>{series.name}</b><br>',
                pointFormat: '{point.x:%e. %b}: {point.y:.2f} m'
            },

            series: [{
                name: 'Winter 2007-2008',
                data: [
                    [Date.UTC(1970,  9, 27), 0   ],
                    [Date.UTC(1970, 10, 10), 0.6 ],
                    [Date.UTC(1970, 10, 18), 0.7 ],
                    [Date.UTC(1970, 11,  2), 0.8 ],
                    [Date.UTC(1970, 11,  9), 0.6 ],
                    [Date.UTC(1970, 11, 16), 0.6 ],
                    [Date.UTC(1970, 11, 28), 0.67],
                    [Date.UTC(1971,  0,  1), 0.81]
                ]
            }

Now this works as intended, but I am trying to add an extra bit of text that will appear in the tooltip when hovering over a point. 现在,这可以按预期工作,但是我想添加一些额外的文本,当将鼠标悬停在某个点上时,这些文本会显示在工具提示中。 This is my desired input for a data point (although I dont know if I will have to change it for my final product). 这是我想要的数据点输入(尽管我不知道是否需要为最终产品进行更改)。

 [Date.UTC(1970, 10, 18), 0.7 , 'custom tooltip1'],
 [Date.UTC(1970, 10, 18), 0.7 , 'custom tooltip2'],

I would want the text displayed in a newline below the current tooltip: 我希望文本显示在当前工具提示下方的换行符中:

当前工具提示

Please let me know if you have any suggestions or can point me somewhere I can find some answers. 如果您有任何建议,或可以指出我可以找到一些答案的地方,请告诉我。

Thanks! 谢谢!

Change your data to be something like this: 将您的数据更改为如下所示:

data: [
   {x: Date.UTC(1970, 10, 18), 
    y: 0.7 ,
    customtooltip: 'custom tooltip1'},
   {x: Date.UTC(1970, 10, 18), 
    y: 0.7 ,
    customtooltip: 'custom tooltip2'}
]

Then in do a tooltip formatter function like this: 然后执行以下工具提示格式化程序功能:

tooltip: {
     formatter: function() {
          var dt = new Date(this.x);
          var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
          var dtstr = dt.getDate()+". "+months[dt.getMonth()];
          var tooltip = '<b>'+this.series.name+'</b><br>'+dtstr+': '+this.y+' m<br>'+this.point.options.customtooltip;
          return tooltip;
     }
}

See how that works for you. 看看如何为您工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM