[英]Highcharts - How to display legend symbol inside the tooltip
I have a problem with Highcharts that I would like to ask. 我对Highcharts有疑问,我想问一下。
I have a Highcharts, and I want to copy the preview symbol from legends to the tooltip. 我有一个Highcharts,我想将预览符号从图例复制到工具提示。
I am doing this in 2 different case: 我在两个不同的情况下这样做:
Extra information: 额外的信息:
<svg>
and I don't actually know how to copy a <svg>
<svg>
,我实际上并不知道如何复制<svg>
Thanks in advance 提前致谢
Here's how to display the the SVG from the legend item in the tooltip (works for columns and pattern fill): 以下是如何从工具提示中的图例项目显示SVG(适用于列和图案填充):
tooltip: {
useHTML: true,
pointFormatter: function() {
var point = this,
series = point.series,
legendSymbol = "<svg width='20' height='20'>" + series.legendSymbol.element.outerHTML + "</svg>";
return legendSymbol + series.name + ": <b>" + point.y + "</b><br/>";
}
}
useHTML
must be enabled to make it work. 必须启用
useHTML
才能使其正常工作。
Live demo: https://jsfiddle.net/kkulig/adr9otbg/ 现场演示: https : //jsfiddle.net/kkulig/adr9otbg/
This goal can be achieve by using pointFormat
or pointFormatter
. 这个目标可以通过使用
pointFormat
或pointFormatter
来实现。 There are couple of example using pointFormatter
, So i will use pointFormat
attribute to achievethis goal.With this approch you dont need to enable useHTML
property. 有几个使用
pointFormatter
的例子,所以我将使用pointFormat
属性来实现这个目标。使用这个approch你不需要启用useHTML
属性。
tooltip: {
pointFormat:
'<svg width="10" height="10" style="color:{series.color}">●</svg>
<b>{series.name}: {point.percentage:.0f}%</b>
<br/>',
shared: true
},
Highcharts.chart("container", { chart: { type: "column" }, title: { text: null }, credits: { enabled: false }, xAxis: { categories: ["Apple", "Orange", "Grapes", "Mango", "Pinapple", "Papaya"], title: "Fruits" }, yAxis: { min: 0, floor: 0, ceiling: 100, title: { text: null }, labels: { align: "right", x: 0, y: -2 } }, tooltip: { pointFormat: '<svg width="10" height="10" style="color:{series.color}">●</svg> <b>{series.name}: {point.percentage:.0f}%</b><br/>', shared: true }, plotOptions: { series: { stacking: "normal" } }, series: [ { name: "Small", data: [5, 3, 4, 7, 2, 3], color: "#A2CD32" }, { name: "Large", data: [2, 2, 3, 2, 1, 2], color: "#FFF500" }, { name: "Medium", data: [3, 4, 4, 2, 5, 2], color: "#FF220" } ] });
<script src="https://code.highcharts.com/highcharts.js"></script> <div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.