top of page

Add additional information in tooltip - (Column, Bar, Line, Area chart)

Sometimes we may need to include more information in tooltip. Here is how we can achieve this.


Steps:

  1. Create column/bar/line/area chart

  2. 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.

  3. Add below widget script and save

  4. 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.






743 views2 comments

Recent Posts

See All
BI Next Level white logo

BI Next Level is your trusted resource for BI customization, data solutions, and expert insights. Explore practical tips, scripts, and tutorials for tools like Sisense, Python, and SQL. Let’s transform your data into impactful insights together.

Quick Links
Connect with us
Copyright © 2024. All Rights Reserved. Designed, Developed & Maintained  by Intertoons
bottom of page