admin管理员组文章数量:1320625
I'm using the heatmap chart from apexcharts and I want to customize the tooltips. For each number of the data I want to provide a matching description as a string. The description values are stored in a simple array like this:
let chartLabels = ['January', 'February', 'March'];
How can I use the custom
field in the chart options to provide the data fields with the custom tooltips?
chartData:
let chartData = {
options: {
chart: {
toolbar: {
show: false
},
},
yaxis: {
show: false
},
xaxis: {
show: false,
labels: {
show: false,
}
},
tooltip: {
enabled: true,
//custom:
},
},
series: [{
name: ' ',
data: [24, 53, 54, 545, 545]
},
{
name: ' ',
data: [654, 454, 454, 44, 34]
}]
};
<Chart
options={chartData.options}
series={chartData.series}
type='heatmap'/>
I'm using the heatmap chart from apexcharts and I want to customize the tooltips. For each number of the data I want to provide a matching description as a string. The description values are stored in a simple array like this:
let chartLabels = ['January', 'February', 'March'];
How can I use the custom
field in the chart options to provide the data fields with the custom tooltips?
chartData:
let chartData = {
options: {
chart: {
toolbar: {
show: false
},
},
yaxis: {
show: false
},
xaxis: {
show: false,
labels: {
show: false,
}
},
tooltip: {
enabled: true,
//custom:
},
},
series: [{
name: ' ',
data: [24, 53, 54, 545, 545]
},
{
name: ' ',
data: [654, 454, 454, 44, 34]
}]
};
<Chart
options={chartData.options}
series={chartData.series}
type='heatmap'/>
Share
Improve this question
asked Feb 5, 2020 at 10:55
NadineNadine
3571 gold badge6 silver badges17 bronze badges
1 Answer
Reset to default 7You should inject the description
in the series data itself to retrieve it easily later when using a custom tooltip. The opts
argument in the custom tooltip contains all the necessary information to retrieve that value as described in the below code.
series: [{
name: "series1"
data: [{
x: "category 1"
y: 10
description: "TEAM A"
}, {
x: "category 2"
y: 20
description: "TEAM B"
}]
}, {
name: "series2"
data: [{
x: "category 3"
y: 10
description: "TEAM C"
}, {
x: "category 4"
y: 20
description: "TEAM D"
}]
}],
tooltip: {
custom: function(opts) {
const desc =
opts.ctx.w.config.series[opts.seriesIndex].data[
opts.dataPointIndex
].description
const value = opts.series[opts.seriesIndex][opts.dataPointIndex]
return desc + ': ' + value
}
},
本文标签: javascriptHow can I set custom tooltips with values of an array in a heatmap apexchartStack Overflow
版权声明:本文标题:javascript - How can I set custom tooltips with values of an array in a heatmap apexchart? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742075299a2419372.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论