我想问一下Highcharts的问题。
我有一个Highcharts,我想将预览符号从图例复制到工具提示。
我在两种不同的情况下这样做:
额外信息:
<svg>
,我实际上并不知道如何复制<svg>
提前致谢
答案 0 :(得分:4)
以下是如何从工具提示中的图例项目显示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
才能使其正常工作。
答案 1 :(得分:0)
可以使用pointFormat
或pointFormatter
来实现此目标。有使用pointFormatter
的两个示例,因此我将使用pointFormat
属性来实现此目标。有了这种方法,您就无需启用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>