最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I set custom tooltips with values of an array in a heatmap apexchart? - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 7

You 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
  }
},
发布评论

评论列表(0)

  1. 暂无评论