cancel
Showing results for 
Search instead for 
Did you mean: 

Change Legend Category Names

jmn3
9 - Travel Pro
9 - Travel Pro

Does anyone know of a script that can be used to change the names of category values for a pie chart?

I have the chart below which uses a binary value and I would like to replace these values with text.

jmn3_0-1654617761654.png

 

5 REPLIES 5

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hi @jmn3 ,

Try this script:

Refer: https://www.binextlevel.com/post/replace-x-axis-labels-in-a-widget

newItemMapping = { '1':'Jan',
				  '2':'Feb',
				  '3':'Mar',
				  '4':'Apr',
				  '5':'May'
				}

widget.on("queryend", function(se, ev){
	
	var panelName = 'Day Number' //Items in this panel will be replaced with new items
	
	panelIndex = ev.rawResult.headers.indexOf(panelName)
	$.each(ev.rawResult.values, function(index, value){

		
		if(newItemMapping[value[panelIndex].text] != undefined)
		{
			value[panelIndex].data = newItemMapping[value[panelIndex].data]
			value[panelIndex].text = newItemMapping[value[panelIndex].text]
		}
	})	
})

- Hari

 

Thank you @harikm007.

I can't see to get this to work on the pie chart. I modified the code to match my data and category name but can't see to get it to work on my pie chart widget:

newItemMapping = { '0':'no scanback',
				  '1':'scanback'
				}

widget.on("queryend", function(se, ev){
	
	var panelName = 'scanback_uploaded' //Items in this panel will be replaced with new items
	
	panelIndex = ev.rawResult.headers.indexOf(panelName)
	$.each(ev.rawResult.values, function(index, value){

		
		if(newItemMapping[value[panelIndex].text] != undefined)
		{
			value[panelIndex].data = newItemMapping[value[panelIndex].data]
			value[panelIndex].text = newItemMapping[value[panelIndex].text]
		}
	})	
})

 

 

 

 

 

harikm007
13 - Data Warehouse
13 - Data Warehouse

Can you share a screenshot of left-side panel of widget? Just to confirm how you added the panel (if there is multiple value panels)?

-Hari

Ophir_Buchman
12 - Data Integration
12 - Data Integration

Hi @jmn3 

One approach is to code the solution (as @harikm007 suggested). The other, is in the data model:

Create a dimension table that contains two columns of 0-false and 1-true and connect it to the binary field. Then - use that field for the pie chart grouping 

Clay
8 - Cloud Apps
8 - Cloud Apps

Hello.  This script works, however it breaks the slice/filter option of the pie charts by adding the custom values to the filter list instead of using the original values when clicked.  Is there a way to modify the script to use the original values for the "click to filter"?

Edit: Removing the line that updates the data portion of the widget seems to have fixed this.  Haven't extensively tested to see if it affects anything else though.

Remove this line: 

value[panelIndex].data = newItemMapping[value[panelIndex].data]