Sometimes we may need to include more information in tooltip. Here is how we can achieve this.
Steps:
Create column/bar/line/area chart
In this approach, result of disabled Values panel will display as additional information in tooltip . So create and disable Values panel as required. Make sure there is only one Values panel is enabled and there is no Categories and Break by panel is disabled.
Add below widget script and save
Refresh widget
widget.on("beforequery", function (se, ev) {
$.each(ev.widget.metadata.panels[1].items, function(index, value){
if(value.disabled == true)
{
var newJaql = {
jaql : JSON.parse(JSON.stringify(value.jaql))
}
ev.query.metadata.push(newJaql)
lastIndex = ev.query.metadata.length - 1
ev.query.metadata[lastIndex].disabled = false
}
})
})
widget.on("beforedatapointtooltip", function (se, args){
var valueSet, breakbyExist = false, categoryExist = false
if(args.widget.metadata.panels[2].items.length > 0)
breakbyExist = true
if(args.widget.metadata.panels[0].items.length > 0)
categoryExist = true
category = args.context.category
seriesName = args.context.points[0].seriesName
if(categoryExist)
{
categoryTitle = args.widget.metadata.panels[0].items[0].jaql.title
categoryIndex = args.widget.rawQueryResult.headers.indexOf(categoryTitle)
}
if(breakbyExist)
{
breakbyTitle = args.widget.metadata.panels[2].items[0].jaql.title
breakByIndex = args.widget.rawQueryResult.headers.indexOf(breakbyTitle)
}
$.each(se.rawQueryResult.values, function(key, value)
{
if(!categoryExist)
{
if(value[breakByIndex].text == seriesName)
{
valueSet = value
}
}else if(!breakbyExist)
{
if(value[categoryIndex].text == category)
{
valueSet = value
}
}else
{
if(value[breakByIndex].text == seriesName && value[categoryIndex].text == category)
{
valueSet = value
}
}
})
$.each(args.widget.metadata.panels[1].items, function(index, value){
if(value.disabled == true)
{
resultIndex = args.widget.rawQueryResult.headers.indexOf(value.jaql.title)
args.context.points[args.context.points.length]= {
seriesName: value.jaql.title,
showPercentage: false,
value: valueSet[resultIndex].text,
valueColor: args.context.points[0].valueColor
}
}
})
})
If you're looking for a more visually appealing and efficient way to display additional information in tooltips, consider rendering a chart. This approach not only enhances the aesthetic appeal but also significantly improves the rendering speed of the tooltip. If you're interested in implementing this solution or would like more details, feel free to reach out.
Below is a GIF showcasing the improved tooltip with a chart. This visual representation highlights the efficiency and aesthetic benefits of this approach.
Super thanks for this useful script to add additional tool tip. I have a scenario where the additional info I need to add is a string and not a number. Hence not able to add it to "Values" panel. Can you please provide a script for adding string as additional information? For example, I can include this additional info in "Category" panel and disable it. Would appreciate a script that can read off disabled category panel?