Forum Discussion

mmalhame's avatar
mmalhame
Cloud Apps
09-19-2024
Solved

How to Use the SwitchDimension Add-On

I am trying to create a line chart for which users can select the 'Break by' dimension. The user should be able to select whether to break out the line chart by choosing 1 of 2 different text fields....
  • harikm007's avatar
    09-20-2024

    Hi mmalhame ,

    I tried the same script in a line chart (just replacing the dimensions with those from my table), and it worked as expected. Here are a few things you might want to double-check:

    1. Field Names: Ensure that the dimension fields you’re using in your script are correct and match exactly with those in your dataset.

    2. Break By Dimension: Make sure you’ve added the “Break By” dimension in the line chart. 

    Also check if there is any error showing in the browser console.

    Here is the script I used:

    prism.registerSwitchDimension({
    	widget: widget,
    	maxItemsBeforeSubMenuIsCreated: 5, //optional
    	dimensions: [
    		{
    			panel: 'break by',
    			affectAllWidgets: true, //optional (true|false)
    			dims: [
    				{
    					"index": 0,
    					"dim": "[Commerce.Age Range]",
    					"datatype": "text",
    					"title": "Applied Rate Class" //optional
    					//"widgetTitleTemplate": "" //optional
    				},
    				{
    					"index": 0,
    					"dim": "[Commerce.Condition]",
    					"datatype": "text",
    					"title": "Approved Rate Class" //optional
    					//"widgetTitleTemplate": "" //optional
    				}
    			]
    		}
    	]
    });

    Result: 

    -Hari