In addition to the properties panel, we can also use scripts to change a chart’s properties.
In this tutorial, we will add scripts to manipulate a chart’s type, visibility and size.
This application contains a bar chart and three buttons.
We will add scripts to each button to change the chart’s properties.
First, we want to be able to switch between a bar chart and a pie chart.
We will use the getChartType() function to detect the chart’s type and then use setChartType() to change it to a pie chart if it is currently a bar chart.
The getChartType() function identifies the the current chart type and checks if it is a vertical stacked bar.
If the chart type is vertical stacked bar, setChartType() changes it to a pie chart and then sets the changes the text and button components accordingly.
If the chart is not vertical stacked bar, then we want the button to let us change it into one, allowing us to toggle between a pie and a bar chart.
Now we will test the script.
Next, we will change the chart’s visibility.
The isVisible() function checks whether the chart is visible or not.
If CHART_1 is not visible, clicking the button will show the chart.
If the chart is visible, clicking the button will  hide the chart.
Now we will test the script.
Next, we will add a script to BUTTON_3 to alter the size of the chart.
Our script will require a variable to check whether the chart has been resized or not.
Note that the default value is false.
If the value of the variable resized is false, clicking the button will change the chart’s height and width to half of the current size
and change the button to say Increase Chart Size.
If the chart has been resized, clicking the button will set the chart back to full size.
Now we will test the script.
You have now modified a chart’s properties with scripting.
For more SAP business intelligence tutorials, visit SAP.com/LearnBI
