Skip to content

tooltip formatter as slot when tooltip.useHTML == true #160

@MathieuDerelle

Description

@MathieuDerelle

would be cool to be able to use slots to construct tooltip when using tooltip.useHTML == true
with the parameters of https://api.highcharts.com/class-reference/Highcharts#.TooltipFormatterCallbackFunction passed like so

<highcharts :options="chartOptions" :callback="someFunction">
  <template v-slot:tooltip="{ instance, tooltip }">
    <table>
                <thead>
                  <tr>
                    <th colspan="3"><b>${instance.x}</b> :</th>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="data in instance.points">
                    <td>
                      <span style="color:${data.point.color}">●</span>
                      ${data.series.name}
                    </td>
                    <td class="text-end px-2">
                      <b>${data.point.y}</b>
                    </td>
                    <td class="text-end">
                      <b>${data.percentage.toFixed(2)} %</b>
                    </td>
                  </tr>
	       </tbody>
    </table>
  </template>
</highcharts>

and be able to encapsulate it in a component :

<highcharts :options="chartOptions" :callback="someFunction">
	<template v-slot:tooltip="{ instance, tooltip }">
		<HighchartTooltip :instance="instance" :tooltip="tooltip" />
	</template>
</highcharts>

writting html in strings is annoying :

          formatter() {
            const body = this.points
              .concat()
              .reverse()
              .filter((data) => data.series.visible)
              .map(
                (data) => `
                  <tr>
                    <td>
                      <span style="color:${data.point.color}">●</span>
                      ${data.series.name}
                    </td>
                    <td class="text-end px-2">
                      <b>${data.point.y}</b>
                    </td>
                    <td class="text-end">
                      <b>${data.percentage.toFixed(2)} %</b>
                    </td>
                  </tr>
                `
              )
              .join('')
            return `
              <table>
                <thead>
                  <tr>
                    <th colspan="3"><b>${this.x}</b> :</th>
                  </tr>
                </thead>
                <tbody>${body}</tbody>
              </table>
            `
          }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions