cancel
Showing results for 
Search instead for 
Did you mean: 

Pie Chart, select 1 particular slice and rest are "Others"

mirzay
8 - Cloud Apps
8 - Cloud Apps

Is there a way to select 1 particular slice of a pie chart and move the rest to "Others". By choosing the Select 1 slice option, it picks up the highest value and moves the rest to others. I want to be able to pick another category of the slice.

1 ACCEPTED SOLUTION

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hi @mirzay ,

Try this:

Set number of slices as 1 and apply below widget script:

harikm007_0-1661329715848.png

widget.on('processresult', function(se, ev) {
	
	itemName = 'Unknown' //set category name here
	
	if(ev.result.series[0].data.length == 2 && ev.result.series[0].data[0].name != itemName)	
	{
		maskFn = ev.result.series[0].data[0].mask
		
		//get object of itemName
		itemIndex = ev.result.series[0].data[1].content.map(el => el.name).indexOf(itemName)
		itemObject = ev.result.series[0].data[1].content[itemIndex]
		currentitemObject = ev.result.series[0].data[0]
		
		//replace first data object with itemName object
		ev.result.series[0].data[0] = JSON.parse(JSON.stringify(itemObject))
		ev.result.series[0].data[0].mask = maskFn
		
		//replace itemName object in 'Others' section with default item
		ev.result.series[0].data[1].content.splice(itemIndex, 1, currentitemObject)
		
		sum = 0
		$.each(ev.result.series[0].data[1].content, function(index, value){
			sum = sum + value.y
			value.x = index
		})
		
		//for displaying categories when click on 'Others' slice
		ev.result.drilldown.series[0].data = ev.result.series[0].data[1].content
		
		ev.result.series[0].data[1].y = sum
		ev.result.series[0].data[1].mathSum = sum
	}

})

-Hari

 

View solution in original post

3 REPLIES 3

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hi @mirzay ,

Try this:

Set number of slices as 1 and apply below widget script:

harikm007_0-1661329715848.png

widget.on('processresult', function(se, ev) {
	
	itemName = 'Unknown' //set category name here
	
	if(ev.result.series[0].data.length == 2 && ev.result.series[0].data[0].name != itemName)	
	{
		maskFn = ev.result.series[0].data[0].mask
		
		//get object of itemName
		itemIndex = ev.result.series[0].data[1].content.map(el => el.name).indexOf(itemName)
		itemObject = ev.result.series[0].data[1].content[itemIndex]
		currentitemObject = ev.result.series[0].data[0]
		
		//replace first data object with itemName object
		ev.result.series[0].data[0] = JSON.parse(JSON.stringify(itemObject))
		ev.result.series[0].data[0].mask = maskFn
		
		//replace itemName object in 'Others' section with default item
		ev.result.series[0].data[1].content.splice(itemIndex, 1, currentitemObject)
		
		sum = 0
		$.each(ev.result.series[0].data[1].content, function(index, value){
			sum = sum + value.y
			value.x = index
		})
		
		//for displaying categories when click on 'Others' slice
		ev.result.drilldown.series[0].data = ev.result.series[0].data[1].content
		
		ev.result.series[0].data[1].y = sum
		ev.result.series[0].data[1].mathSum = sum
	}

})

-Hari

 

Hi Harikm007,

What's the procedure to achieve this for any other viz apart from pie chart.
For eg, I want to show top 10 categories based on sales and show rest as 'Others' in a bar/column chart.

Any idea around these..
Thank you

mirzay
8 - Cloud Apps
8 - Cloud Apps

Works great. Thank you @harikm007