我想知道可以使用列颜色调整工具提示文本吗?
例如,如果我的列是蓝色的,那么我的工具提示标题将是“蓝色标题”,如果它是橙色,则工具提示标题将为“橙色标题”。
这可能吗?
提前致谢!
答案 0 :(得分:0)
可以使用工具提示格式化程序,从系列中获取颜色并返回包含系列颜色值的自定义样式的范围。
const options = {
chart: { type: 'column' },
series: [...Array(5)].map(() => ({ data: [...Array(3)].map(Math.random) })),
tooltip: {
formatter () {
return `<span style="color: ${this.series.color}">
My new tooltip
x: ${this.x} y: ${this.y}
</span>`
}
}
}
const chart = Highcharts.chart('container', options)
答案 1 :(得分:0)
最后我自己找到了一个解决方案,只是我犯了一个小错误。
这是我的解决方案:
tooltip: {
formatter: function () {
if (this.color == "#d8662c") {
return '<b>Title 1</b>';
} else if (this.color == "#009dc1") {
return '<b>Title 2</b>';
} else {
return return '<b>Title 3</b>';
}
}
}