Tooltip for Pie Charts
Hello DRay Liliia_DevX harikm007 ,
I saw harikm007 other post about adding tooltip information to bar chart, column chart, etc, but I was wondering if there was code out there to add it to a pie chart (https://community.sisense.com/t5/build-analytics/add-additional-information-in-tooltip-column-bar-line-area/m-p/2538)?
My attempt at it using ChatGPT:
// Add CART ID count to the query
widget.on("beforequery", function (se, ev) {
var newJaql = {
jaql: {
column: "CART ID",
agg: "count",
datatype: "numeric",
dim: "[GMV_ORDER_DASH_UNION.CART ID]",
table: "GMV_ORDER_DASH_UNION",
title: "Cart Count"
}
};
ev.query.metadata.push(newJaql);
});
// Modify the tooltip content
widget.on("beforedatapointtooltip", function (se, args) {
// Find the Cart Count index in the results
var cartCountIndex = se.rawQueryResult.headers.indexOf("Cart Count");
if (cartCountIndex !== -1) {
// For pie charts, we need to match the category
var category = args.context.category;
var categoryIndex = se.rawQueryResult.headers.indexOf(se.metadata.panels[0].items[0].jaql.title);
// Find the matching row for this pie slice
for (var i = 0; i < se.rawQueryResult.values.length; i++) {
var row = se.rawQueryResult.values[i];
if (row[categoryIndex].text === category) {
// Add Cart Count to the tooltip
args.context.points.push({
seriesName: "Cart Count",
showPercentage: false,
value: row[cartCountIndex].text,
valueColor: args.context.points[0].valueColor
});
break;
}
}
}
});
As you expected this does not work. Any possible ideas would be much appreciated.
Hi Astroraf,
The Additional Data Chart Tooltip plugin can be used to add additional measures to the tooltip on Pie charts (as well as Column, Bar, Line, Area, and Polar charts). The article mentions that the plugin works only for Column charts, but this is inaccurate. We'll update it as soon as possible.
The implementation is actually simpler for Pie charts because the plugin adds an additional panel to the widget editor where you can add the measure(s) to add to the tooltip. See screenshot below for reference. Let me know if this is helpful.
-Tri
Hi Astroraf ,
I’d like to add to TriAnthony’s recommendation by noting that the suggested plugin is a community-developed one. Community plugins often break when upgrading Sisense versions, which can lead to unexpected issues.
To stay on the safe side, I highly recommend checking out our officially supported and FREE Advanced Tooltip plugin. Once installed, you can easily enable tooltips for all widget types and customize them with any combination of dimensions and measures.
And the best part? You can fully style the tooltip to match your dashboard and brand identity.
Feel free to reach out to us at [email protected] to get it. Hope this helps! 😊