Example shows Vuejs Stacked Area Chart with shared tooltip to show information of all the datapoints having common x value.
/* App.vue */
<script>
export default {
data() {
return {
options: {
theme: "light2",
exportEnabled: true,
title: {
text: "Sales Order Analysis"
},
axisX: {
valueFormatString: "MMM",
interval: 1,
intervalType: "month"
},
axisY: {
title: "Units Sold"
},
toolTip: {
shared: true
},
legend: {
cursor: "pointer",
itemclick: function (e) {
if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
} else {
e.dataSeries.visible = true;
}
e.chart.render();
}
},
data: [{
type: "stackedArea",
name: "Smart TV",
color: "#0D47A1",
showInLegend: "true",
xValueFormatString: "MMM YYYY",
toolTipContent: "{x}<br/><b><span style='\"'color: {color};'\"'>{name}</span></b>: {y}",
dataPoints: [
{ x: new Date(2021, 0, 1), y: 20},
{ x: new Date(2021, 1, 1), y: 40},
{ x: new Date(2021, 2, 1), y: 60},
{ x: new Date(2021, 3, 1), y: 50},
{ x: new Date(2021, 4, 1), y: 55},
{ x: new Date(2021, 5, 1), y: 65},
{ x: new Date(2021, 6, 1), y: 69},
{ x: new Date(2021, 7, 1), y: 75},
{ x: new Date(2021, 8, 1), y: 120},
{ x: new Date(2021, 9, 1), y: 90},
{ x: new Date(2021, 10, 1), y: 95},
{ x: new Date(2021, 11, 1), y: 110}
]
},
{
type: "stackedArea",
name: "Mobile",
color: "#1976D2",
showInLegend: "true",
toolTipContent: "<b><span style='\"'color: {color};'\"'>{name}</span></b>: {y}",
dataPoints: [
{ x: new Date(2021, 0, 1), y: 55},
{ x: new Date(2021, 1, 1), y: 75},
{ x: new Date(2021, 2, 1), y: 83},
{ x: new Date(2021, 3, 1), y: 95},
{ x: new Date(2021, 4, 1), y: 90},
{ x: new Date(2021, 5, 1), y: 95},
{ x: new Date(2021, 6, 1), y: 110},
{ x: new Date(2021, 7, 1), y: 114},
{ x: new Date(2021, 8, 1), y: 170},
{ x: new Date(2021, 9, 1), y: 150},
{ x: new Date(2021, 10, 1), y: 155},
{ x: new Date(2021, 11, 1), y: 210}
]
},
{
type: "stackedArea",
name: "Tablet",
color: "#2196F3",
showInLegend: "true",
toolTipContent: "<b><span style='\"'color: {color};'\"'>{name}</span></b>: {y}",
dataPoints: [
{ x: new Date(2021, 0, 1), y: 30},
{ x: new Date(2021, 1, 1), y: 45},
{ x: new Date(2021, 2, 1), y: 70},
{ x: new Date(2021, 3, 1), y: 60},
{ x: new Date(2021, 4, 1), y: 65},
{ x: new Date(2021, 5, 1), y: 70},
{ x: new Date(2021, 6, 1), y: 78},
{ x: new Date(2021, 7, 1), y: 80},
{ x: new Date(2021, 8, 1), y: 95},
{ x: new Date(2021, 9, 1), y: 92},
{ x: new Date(2021, 10, 1), y: 97},
{ x: new Date(2021, 11, 1), y: 120}
]
}]
},
styleOptions: {
width: "100%",
height: "360px"
}
}
}
}
</script>
<template>
<CanvasJSChart :options="options" :style="styleOptions" />
</template>
You can customize the content tooltip for each dataseries using toolTipContent property. Format x-values and y-values in tooltip and index label using xValueFormatString and yValueFormatString.
Note For step by step instructions, follow our Vuejs Integration Tutorial