To switch to a line chart when Checked is true, or to a pie chart when Checked is false:
Add a new check box to Limits Dashboard, and use the Properties dialog box to change the Title to Switch Chart To Line Chart and the Name to chk_ChartType2.
Open the Script Editor on the new Switch Chart To Line Chart check box. [F8]
Type switch () a return [Enter], an open curly bracket ({), two returns [Enter], and a close curly bracket (}).
The parentheses are for the expression. The curly brackets are for the body of the switch.
Click inside the expression parentheses, and then use the Object browser to navigate to Limits Dashboard Objects, then chk_ChartType2 Properties and then double-click Checked.
The Description pane shows Property Checked as Boolean. Since there are two Boolean values (true and false), we will provide two case values.
In the body of the switch, add the case for a value of true, and the statement to change the Limits Chart to a Line chart.
Click inside the body of the switch (on the blank line between the curly brackets), type case true : and a return [Enter].
Navigate to Application, then ActiveDocument, then Sections, then Limits Chart then Properties and then double-click ChartType.
The Description pane shows Property ChartType as BqChartType. Find the collection for BqChartType in the object model under Constants.
After ChartType, type an equal sign (=), then navigate to Constants, then BqChartType, then and double-click bqChartTypeLine.
Type a semicolon (;) at the end of the statement, and a return [Enter].
Type break; and two returns [Enter].
switch (chk_ChartType2.Checked) { case true : ActiveDocument.Sections["Limits Chart"].ChartType=bqChartTypeLine; break; }
The case for true changes the chart to a line chart and ends with a break statement so other cases are ignored. The extra return is for readability.
Add the case for a value of false, and the statement to change the Limits Chart to a pie chart.
Click inside the body of the switch (on the blank line above the closing curly bracket), type case false : and a return [Enter].
Use the Object browser to navigate to Application, then ActiveDocument, then Sections, then Limit Charts, and then double-click ChartType.
After ChartType, type an equal sign (=), and then navigate to Constants, then BqChartType, and then double-click bqChartTypePie.
Type a semicolon (;) at the end of the statement, and a return [Enter].
Type break; and a return [Enter].
switch (chk_ChartType2.Checked) { case true : ActiveDocument.Sections["Limits Chart"].ChartType=bqChartTypeLine; break; case false : ActiveDocument.Sections["Limits Chart"].ChartType=bqChartTypePie; break; }
Verify that there is a close curly bracket after the last case.
Toggle to Run mode to test the script.
The chart should work the same with the switch as with the if...else logic. When the check box is selected, the chart is a line chart; when the check box is cleared, the chart is a pie chart.
DropDown1 (under Select View) of The Plan and Actual section of Sample2mod.bqy allows the user to change the Costs, Sold, and Revenue charts to display results in terms of Planned vs. Actual, Planned, or Actual.
The OnClick event for DropDown1 creates a variable for the user choice. Then, depending on the value of choice, the JavaScript goes through each chart and removes all facts, and adds the appropriate facts. This is done with an if...else control structure.
In Design mode, with the Console window closed, copy and paste DropDown1 and rename the new one DropDown1_switch. Change the if...else control structure to a switch. (See Controlling Chart Facts with if...else and Controlling Chart Facts with switch for the finished JavaScript scripts.)