Tool tip in Vue Pivotview component

8 Aug 20236 minutes to read

The tooltip can be enabled or disabled by setting the showTooltip property to true or false. By default, tooltip is enabled in the pivot table.

<template>
    <div id="app">
        <ejs-pivotview :height="height" :dataSourceSettings="dataSourceSettings" :showTooltip="showTooltip"> </ejs-pivotview>
    </div>
</template>

<script>
import Vue from "vue";
import { PivotViewPlugin } from "@syncfusion/ej2-vue-pivotview";
import { pivotData } from './pivotData.js';

Vue.use(PivotViewPlugin);

export default {
  data () {
    return {
      dataSourceSettings: {
        dataSource: pivotData,
        expandAll: false,
        enableSorting: true,
        drilledMembers: [{ name: 'Year', items: ['FY 2015'] }, { name: 'Country', items: ['France'] }],
        columns: [{ name: 'Year', caption: 'Production Year' }, { name: 'Quarter' }],
        values: [{ name: 'Sold', caption: 'Units Sold' }, { name: 'Amount', caption: 'Sold Amount' }],
        rows: [{ name: 'Country' }, { name: 'Products' }],
        formatSettings: [{ name: 'Amount', format: 'C0' }],
        filters: []
      },
      height: 350,
      showTooltip: false
    }
  }
}
</script>
<style>
@import "@syncfusion/ej2-vue-pivotview/styles/material.css";
</style>

Tooltip Template

User can design their own tooltip by setting the property tooltipTemplate with own HTML elements. The property accepts both HTML string and ID attribute. The following place holders are available to display its dynamic values inside the HTML elements.

${rowHeaders} – Row headers of the selected value cell.

${columnHeaders} – Column headers of the selected value cell.

${rowFields} – Row fields of the selected value cell.

${columnFields} – Column fields of the selected value cell.

${valueField} – Field name of the selected value cell.

${aggregateType} – Aggregate type of the selected value cell.

${value} - Formatted value of the selected value cell.

The tooltip customization is common for both pivot table and pivot chart or it can be done individually as well. To customize the pivot table tooltip, the above procedure needs to be followed. To customize the pivot chart tooltip alone use template property of tooltip under chartSettings.

In the below sample, the pivot table and pivot chart shows customized tooltip layouts.

<template>
    <div id="app">
        <ejs-pivotview :dataSourceSettings="dataSourceSettings" :displayOption="displayOption" :chartSettings="chartSettings" :toolbar="toolbar" :showToolbar="showToolbar" :tooltipTemplate="tooltipTemplate"> </ejs-pivotview>
    </div>
</template>

<script>
import Vue from "vue";
import { PivotViewPlugin, Toolbar} from "@syncfusion/ej2-vue-pivotview";
import { pivotData } from './pivotData.js';

Vue.use(PivotViewPlugin);

export default {
  data () {
    return {
      dataSourceSettings: {
        dataSource: pivotData,
        columns: [{ name: 'Year', caption: 'Production Year' }, { name: 'Quarter' }],
        values: [{ name: 'Sold', caption: 'Units Sold' }, { name: 'Amount', caption: 'Sold Amount' }],
        rows: [{ name: 'Country' }, { name: 'Products' }],
        filters: []
    },
    height: 350,
    displayOption: { view: 'Both' },
    chartSettings: {
        value: 'Amount', enableExport: true, chartSeries: { type: 'Column', animation: { enable: false } }, enableMultipleAxis: false,
        tooltip: { template: '<span class="pivotTooltipTemplateWrap">${aggregateType} of ${valueField}: ${value}</span>' }
    },
        toolbar: ['Grid', 'Chart'],
        showToolbar: true,
        tooltipTemplate: `<div class='pivotTooltipTemplateWrap'><span class='pivotTooltipHeader'>`+"${columnHeaders}"+`:</span ><span class='pivotTooltipValue'>`+"${value}"+`</span></div>`
    }
  },
  provide: {
      pivotview: [Toolbar]
  }
}
</script>
<style>
@import "@syncfusion/ej2-vue-pivotview/styles/material.css";
.pivotTooltipTemplateWrap {
  border: 3px solid #27b1f0;
  background-color: #4d4d4d;
  width: auto;
  color: #FFFFFF;
  padding: 5px;
  font-size: 12px;
}

.pivotTooltipValue {
  font-style: italic;
}

.pivotTooltipHeader {
  color: aqua;
  font-weight: bold;
  width: 100px;
}
</style>