Tooltip in Vue HeatMap Chart
Tooltip is used to provide the details of the heatmap cell, and this can be displayed, while hovering the cursor over the cell or performing tap action in touch devices.
Default tooltip
You can enable the tooltip by setting the showTooltip property to true and injecting the Tooltip module into the provide.
<template>
<div id="app">
<ejs-heatmap id="heatmap" :titleSettings='titleSettings' :xAxis='xAxis' :yAxis='yAxis' :dataSource='dataSource'
:cellSettings='cellSettings' :showTooltip='showTooltip'></ejs-heatmap>
</div>
</template>
<script setup>
import { provide } from "vue";
import { HeatMapComponent as EjsHeatmap, Tooltip, Legend } from '@syncfusion/ej2-vue-heatmap';
const dataSource = [
[0.72, 0.71, 0.71, 0.67, 0.72, 0.53, 0.53, 0.56, 0.58, 0.56],
[2.28, 2.29, 2.09, 1.84, 1.64, 1.49, 1.49, 1.39, 1.32, 1.23],
[2.02, 2.17, 2.30, 2.39, 2.36, 2.52, 2.62, 2.57, 2.57, 2.74],
[3.21, 3.26, 3.45, 3.47, 3.42, 3.34, 3.14, 2.83, 2.64, 2.61],
[3.22, 3.13, 3.04, 2.95, 2.69, 2.49, 2.27, 2.18, 2.06, 1.87],
[3.30, 3.39, 3.40, 3.48, 3.60, 3.67, 3.73, 3.79, 3.79, 4.07],
[5.80, 5.74, 5.64, 5.44, 5.18, 5.08, 5.07, 5.00, 5.35, 5.47],
[6.91, 7.40, 8.13, 8.80, 9.04, 9.24, 9.43, 9.35, 9.49, 9.69]
];
const titleSettings = {
text: 'Crude Oil Production of Non-OPEC Countries (in Million barrels per day)',
textStyle: {
size: '15px',
fontWeight: '500',
fontStyle: 'Normal',
fontFamily: 'Segoe UI'
}
};
const xAxis = {
labels: ['Canada', 'China', 'Egypt', 'Mexico', 'Norway', 'Russia', 'UK', 'USA']
};
const yAxis = {
labels: ['2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010']
};
const cellSettings = {
showLabel: false,
};
const showTooltip = true;
provide('heatmap', [Tooltip, Legend])
</script><template>
<div id="app">
<ejs-heatmap id="heatmap" :titleSettings='titleSettings' :xAxis='xAxis' :yAxis='yAxis' :dataSource='dataSource'
:cellSettings='cellSettings' :showTooltip='showTooltip'></ejs-heatmap>
</div>
</template>
<script>
import { HeatMapComponent, Tooltip, Legend } from '@syncfusion/ej2-vue-heatmap';
export default {
name: "App",
components: {
"ejs-heatmap": HeatMapComponent
},
data: function () {
return {
dataSource: [
[0.72, 0.71, 0.71, 0.67, 0.72, 0.53, 0.53, 0.56, 0.58, 0.56],
[2.28, 2.29, 2.09, 1.84, 1.64, 1.49, 1.49, 1.39, 1.32, 1.23],
[2.02, 2.17, 2.30, 2.39, 2.36, 2.52, 2.62, 2.57, 2.57, 2.74],
[3.21, 3.26, 3.45, 3.47, 3.42, 3.34, 3.14, 2.83, 2.64, 2.61],
[3.22, 3.13, 3.04, 2.95, 2.69, 2.49, 2.27, 2.18, 2.06, 1.87],
[3.30, 3.39, 3.40, 3.48, 3.60, 3.67, 3.73, 3.79, 3.79, 4.07],
[5.80, 5.74, 5.64, 5.44, 5.18, 5.08, 5.07, 5.00, 5.35, 5.47],
[6.91, 7.40, 8.13, 8.80, 9.04, 9.24, 9.43, 9.35, 9.49, 9.69]
],
titleSettings: {
text: 'Crude Oil Production of Non-OPEC Countries (in Million barrels per day)',
textStyle: {
size: '15px',
fontWeight: '500',
fontStyle: 'Normal',
fontFamily: 'Segoe UI'
}
},
xAxis: {
labels: ['Canada', 'China', 'Egypt', 'Mexico', 'Norway', 'Russia', 'UK', 'USA']
},
yAxis: {
labels: ['2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010']
},
cellSettings: {
showLabel: false,
},
showTooltip: true
}
},
provide: {
heatmap: [Tooltip, Legend]
}
}
</script>Tooltip template
In heatmap, you can customize the tooltip using the tooltipRender client side event.
<template>
<div id="app">
<ejs-heatmap id="heatmap" :titleSettings='titleSettings' :xAxis='xAxis' :yAxis='yAxis' :dataSource='dataSource'
:cellSettings='cellSettings' :showTooltip='showTooltip' :tooltipRender='tooltipRender'></ejs-heatmap>
</div>
</template>
<script setup>
import { provide } from "vue";
import { HeatMapComponent as EjsHeatmap, Tooltip, Legend } from '@syncfusion/ej2-vue-heatmap';
const dataSource = [
[0.72, 0.71, 0.71, 0.67, 0.72, 0.53, 0.53, 0.56, 0.58, 0.56],
[2.28, 2.29, 2.09, 1.84, 1.64, 1.49, 1.49, 1.39, 1.32, 1.23],
[2.02, 2.17, 2.30, 2.39, 2.36, 2.52, 2.62, 2.57, 2.57, 2.74],
[3.21, 3.26, 3.45, 3.47, 3.42, 3.34, 3.14, 2.83, 2.64, 2.61],
[3.22, 3.13, 3.04, 2.95, 2.69, 2.49, 2.27, 2.18, 2.06, 1.87],
[3.30, 3.39, 3.40, 3.48, 3.60, 3.67, 3.73, 3.79, 3.79, 4.07],
[5.80, 5.74, 5.64, 5.44, 5.18, 5.08, 5.07, 5.00, 5.35, 5.47],
[6.91, 7.40, 8.13, 8.80, 9.04, 9.24, 9.43, 9.35, 9.49, 9.69]
];
const titleSettings = {
text: 'Crude Oil Production of Non-OPEC Countries (in Million barrels per day)',
textStyle: {
size: '15px',
fontWeight: '500',
fontStyle: 'Normal',
fontFamily: 'Segoe UI'
}
};
const xAxis = {
labels: ['Canada', 'China', 'Egypt', 'Mexico', 'Norway', 'Russia', 'UK', 'USA']
};
const yAxis = {
labels: ['2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010']
};
const cellSettings = {
showLabel: false,
};
const showTooltip = true;
const tooltipRender = (args) => {
args.content = ['In ' + args.yLabel + ', the ' + args.xLabel + ' produced ' + args.value + ' million barrels per day'];
}
provide('heatmap', [Tooltip, Legend])
</script><template>
<div id="app">
<ejs-heatmap id="heatmap" :titleSettings='titleSettings' :xAxis='xAxis' :yAxis='yAxis' :dataSource='dataSource'
:cellSettings='cellSettings' :showTooltip='showTooltip' :tooltipRender='tooltipRender'></ejs-heatmap>
</div>
</template>
<script>
import { HeatMapComponent, Tooltip, Legend } from '@syncfusion/ej2-vue-heatmap';
export default {
name: "App",
components: {
"ejs-heatmap": HeatMapComponent
},
data: function () {
return {
dataSource: [
[0.72, 0.71, 0.71, 0.67, 0.72, 0.53, 0.53, 0.56, 0.58, 0.56],
[2.28, 2.29, 2.09, 1.84, 1.64, 1.49, 1.49, 1.39, 1.32, 1.23],
[2.02, 2.17, 2.30, 2.39, 2.36, 2.52, 2.62, 2.57, 2.57, 2.74],
[3.21, 3.26, 3.45, 3.47, 3.42, 3.34, 3.14, 2.83, 2.64, 2.61],
[3.22, 3.13, 3.04, 2.95, 2.69, 2.49, 2.27, 2.18, 2.06, 1.87],
[3.30, 3.39, 3.40, 3.48, 3.60, 3.67, 3.73, 3.79, 3.79, 4.07],
[5.80, 5.74, 5.64, 5.44, 5.18, 5.08, 5.07, 5.00, 5.35, 5.47],
[6.91, 7.40, 8.13, 8.80, 9.04, 9.24, 9.43, 9.35, 9.49, 9.69]
],
titleSettings: {
text: 'Crude Oil Production of Non-OPEC Countries (in Million barrels per day)',
textStyle: {
size: '15px',
fontWeight: '500',
fontStyle: 'Normal',
fontFamily: 'Segoe UI'
}
},
xAxis: {
labels: ['Canada', 'China', 'Egypt', 'Mexico', 'Norway', 'Russia', 'UK', 'USA']
},
yAxis: {
labels: ['2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010']
},
cellSettings: {
showLabel: false,
},
showTooltip: true
}
},
provide: {
heatmap: [Tooltip, Legend]
},
methods: {
tooltipRender: function (args) {
args.content = ['In ' + args.yLabel + ', the ' + args.xLabel + ' produced ' + args.value + ' million barrels per day'];
}
}
}
</script>Customize the appearance of Tooltip
The fill and border properties are used to customize the background color and border of the Tooltip respectively. The textStyle property in the Tooltip is used to customize the font of the tooltip text.
<template>
<div id="app">
<ejs-heatmap id="heatmap" :titleSettings='titleSettings' :xAxis='xAxis' :yAxis='yAxis' :dataSource='dataSource'
:cellSettings='cellSettings' :showTooltip='showTooltip' :paletteSettings='paletteSettings'
:tooltipSettings='tooltipSettings' :tooltipRender='tooltipRender'></ejs-heatmap>
</div>
</template>
<script setup>
import { provide } from "vue";
import { HeatMapComponent as EjsHeatmap, Tooltip, Legend } from '@syncfusion/ej2-vue-heatmap';
const dataSource = [
[0.72, 0.71, 0.71, 0.67, 0.72, 0.53, 0.53, 0.56, 0.58, 0.56],
[2.28, 2.29, 2.09, 1.84, 1.64, 1.49, 1.49, 1.39, 1.32, 1.23],
[2.02, 2.17, 2.30, 2.39, 2.36, 2.52, 2.62, 2.57, 2.57, 2.74],
[3.21, 3.26, 3.45, 3.47, 3.42, 3.34, 3.14, 2.83, 2.64, 2.61],
[3.22, 3.13, 3.04, 2.95, 2.69, 2.49, 2.27, 2.18, 2.06, 1.87],
[3.30, 3.39, 3.40, 3.48, 3.60, 3.67, 3.73, 3.79, 3.79, 4.07],
[5.80, 5.74, 5.64, 5.44, 5.18, 5.08, 5.07, 5.00, 5.35, 5.47],
[6.91, 7.40, 8.13, 8.80, 9.04, 9.24, 9.43, 9.35, 9.49, 9.69]
];
const titleSettings = {
text: 'Crude Oil Production of Non-OPEC Countries (in Million barrels per day)',
textStyle: {
size: '15px',
fontWeight: '500',
fontStyle: 'Normal',
fontFamily: 'Segoe UI'
}
};
const xAxis = {
labels: ['Canada', 'China', 'Egypt', 'Mexico', 'Norway', 'Russia', 'UK', 'USA']
};
const yAxis = {
labels: ['2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010']
};
const cellSettings = {
showLabel: false,
};
const paletteSettings = {
palette: [
{ color: '#F0ADCE' },
{ color: '#19307B' }
]
};
const tooltipSettings = {
fill: '#696295',
textStyle: {
color: '#FFFFFF',
size: '12px'
},
border: {
width: 2,
color: '#F0C27B'
}
};
const showTooltip = true;
const tooltipRender = (args) => {
args.content = ['In ' + args.yLabel + ', the ' + args.xLabel + ' produced ' + args.value + ' million barrels per day'];
}
provide('heatmap', [Tooltip, Legend])
</script><template>
<div id="app">
<ejs-heatmap id="heatmap" :titleSettings='titleSettings' :xAxis='xAxis' :yAxis='yAxis' :dataSource='dataSource'
:cellSettings='cellSettings' :showTooltip='showTooltip' :paletteSettings='paletteSettings'
:tooltipSettings='tooltipSettings' :tooltipRender='tooltipRender'></ejs-heatmap>
</div>
</template>
<script>
import { HeatMapComponent, Tooltip, Legend } from '@syncfusion/ej2-vue-heatmap';
export default {
name: "App",
components: {
"ejs-heatmap": HeatMapComponent
},
data: function () {
return {
dataSource: [
[0.72, 0.71, 0.71, 0.67, 0.72, 0.53, 0.53, 0.56, 0.58, 0.56],
[2.28, 2.29, 2.09, 1.84, 1.64, 1.49, 1.49, 1.39, 1.32, 1.23],
[2.02, 2.17, 2.30, 2.39, 2.36, 2.52, 2.62, 2.57, 2.57, 2.74],
[3.21, 3.26, 3.45, 3.47, 3.42, 3.34, 3.14, 2.83, 2.64, 2.61],
[3.22, 3.13, 3.04, 2.95, 2.69, 2.49, 2.27, 2.18, 2.06, 1.87],
[3.30, 3.39, 3.40, 3.48, 3.60, 3.67, 3.73, 3.79, 3.79, 4.07],
[5.80, 5.74, 5.64, 5.44, 5.18, 5.08, 5.07, 5.00, 5.35, 5.47],
[6.91, 7.40, 8.13, 8.80, 9.04, 9.24, 9.43, 9.35, 9.49, 9.69]
],
titleSettings: {
text: 'Crude Oil Production of Non-OPEC Countries (in Million barrels per day)',
textStyle: {
size: '15px',
fontWeight: '500',
fontStyle: 'Normal',
fontFamily: 'Segoe UI'
}
},
xAxis: {
labels: ['Canada', 'China', 'Egypt', 'Mexico', 'Norway', 'Russia', 'UK', 'USA']
},
yAxis: {
labels: ['2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010']
},
cellSettings: {
showLabel: false,
},
paletteSettings: {
palette: [
{ color: '#F0ADCE' },
{ color: '#19307B' }
]
},
tooltipSettings: {
fill: '#696295',
textStyle: {
color: '#FFFFFF',
size: '12px'
},
border: {
width: 2,
color: '#F0C27B'
}
},
showTooltip: true
}
},
provide: {
heatmap: [Tooltip, Legend]
},
methods: {
tooltipRender: function (args) {
args.content = ['In ' + args.yLabel + ', the ' + args.xLabel + ' produced ' + args.value + ' million barrels per day'];
}
}
}
</script>Access the datasource record in the tooltip
The complete datasource record associated with a hovered HeatMap cell can be accessed using the data property in the tooltipRender event arguments. The value property contains only the rendered cell value, whereas the data property contains the corresponding datasource record. This allows additional mapped or unmapped fields from the datasource to be used when customizing the tooltip content without modifying the underlying datasource.
The value returned through the data property depends on the datasource binding type:
- In JSON cell binding, it contains the complete JSON object associated with the hovered cell.
- In JSON table binding, it contains the complete JSON row object associated with the hovered cell.
- In array cell binding, it contains the complete array associated with the hovered cell.
- In array table binding, it contains the complete row array associated with the hovered cell.
The following example demonstrates how to access the complete datasource record through the data property and use its additional fields to customize the tooltip content.
<template>
<div id="app">
<ejs-heatmap id="heatmap" :titleSettings='titleSettings' :xAxis='xAxis' :yAxis='yAxis'
:dataSource='dataSource' :dataSourceSettings='dataSourceSettings' :cellSettings='cellSettings'
:showTooltip='true' :tooltipRender='tooltipRender'></ejs-heatmap>
</div>
</template>
<script setup>
import { provide } from "vue";
import { HeatMapComponent as EjsHeatmap, Tooltip, Legend, Adaptor } from '@syncfusion/ej2-vue-heatmap';
const dataSource = [
{ employee: 'Nancy', month: 'Jan', revenue: 73, target: 70, region: 'North America' },
{ employee: 'Nancy', month: 'Feb', revenue: 39, target: 50, region: 'North America' },
{ employee: 'Nancy', month: 'Mar', revenue: 26, target: 45, region: 'North America' },
{ employee: 'Andrew', month: 'Jan', revenue: 93, target: 80, region: 'Europe' },
{ employee: 'Andrew', month: 'Feb', revenue: 58, target: 55, region: 'Europe' },
{ employee: 'Andrew', month: 'Mar', revenue: 53, target: 60, region: 'Europe' },
{ employee: 'Janet', month: 'Jan', revenue: 99, target: 90, region: 'Asia Pacific' },
{ employee: 'Janet', month: 'Feb', revenue: 28, target: 40, region: 'Asia Pacific' },
{ employee: 'Janet', month: 'Mar', revenue: 22, target: 35, region: 'Asia Pacific' }
];
const dataSourceSettings = {
isJsonData: true,
adaptorType: 'Cell',
xDataMapping: 'employee',
yDataMapping: 'month',
valueMapping: 'revenue'
};
const titleSettings = {
text: 'Sales Revenue per Employee (in 1000 US$)',
textStyle: {
size: '15px',
fontWeight: '500',
fontStyle: 'Normal',
fontFamily: 'Segoe UI'
}
};
const xAxis = {
labels: ['Nancy', 'Andrew', 'Janet']
};
const yAxis = {
labels: ['Jan', 'Feb', 'Mar']
};
const cellSettings = {
showLabel: true,
format: '${value}K'
};
const tooltipRender = (args) => {
const record = args.data;
if (record) {
args.content = [
'Employee: ' + record.employee +
'<br/>Month: ' + record.month +
'<br/>Revenue: $' + record.revenue + 'K' +
'<br/>Target: $' + record.target + 'K' +
'<br/>Region: ' + record.region
];
}
};
provide('heatmap', [Adaptor, Tooltip, Legend]);
</script><template>
<div id="app">
<ejs-heatmap id="heatmap" :titleSettings='titleSettings' :xAxis='xAxis' :yAxis='yAxis'
:dataSource='dataSource' :dataSourceSettings='dataSourceSettings' :cellSettings='cellSettings'
:showTooltip='true' :tooltipRender='tooltipRender'></ejs-heatmap>
</div>
</template>
<script>
import { HeatMapComponent, Tooltip, Legend, Adaptor } from '@syncfusion/ej2-vue-heatmap';
export default {
name: "App",
components: {
"ejs-heatmap": HeatMapComponent
},
data: function () {
return {
dataSource: [
{ employee: 'Nancy', month: 'Jan', revenue: 73, target: 70, region: 'North America' },
{ employee: 'Nancy', month: 'Feb', revenue: 39, target: 50, region: 'North America' },
{ employee: 'Nancy', month: 'Mar', revenue: 26, target: 45, region: 'North America' },
{ employee: 'Andrew', month: 'Jan', revenue: 93, target: 80, region: 'Europe' },
{ employee: 'Andrew', month: 'Feb', revenue: 58, target: 55, region: 'Europe' },
{ employee: 'Andrew', month: 'Mar', revenue: 53, target: 60, region: 'Europe' },
{ employee: 'Janet', month: 'Jan', revenue: 99, target: 90, region: 'Asia Pacific' },
{ employee: 'Janet', month: 'Feb', revenue: 28, target: 40, region: 'Asia Pacific' },
{ employee: 'Janet', month: 'Mar', revenue: 22, target: 35, region: 'Asia Pacific' }
],
dataSourceSettings: {
isJsonData: true,
adaptorType: 'Cell',
xDataMapping: 'employee',
yDataMapping: 'month',
valueMapping: 'revenue'
},
titleSettings: {
text: 'Sales Revenue per Employee (in 1000 US$)',
textStyle: {
size: '15px',
fontWeight: '500',
fontStyle: 'Normal',
fontFamily: 'Segoe UI'
}
},
xAxis: {
labels: ['Nancy', 'Andrew', 'Janet']
},
yAxis: {
labels: ['Jan', 'Feb', 'Mar']
},
cellSettings: {
showLabel: true,
format: '${value}K'
}
}
},
methods: {
tooltipRender: function (args) {
const record = args.data;
if (record) {
args.content = [
'Employee: ' + record.employee +
'<br/>Month: ' + record.month +
'<br/>Revenue: $' + record.revenue + 'K' +
'<br/>Target: $' + record.target + 'K' +
'<br/>Region: ' + record.region
];
}
}
},
provide: {
heatmap: [Adaptor, Tooltip, Legend]
}
}
</script>Note: To use tooltip feature, we need to inject
Tooltipmodule into theprovide.