Exercise

Add a new check box to the Limits Dashboard section of Sample1mod.bqy. Add an if statement that shows the chart legend when the check box is selected, and hides it when the check box is not selected.

ShowLegend requires a Boolean (true or false) assignment. The statement to show the chart legend is:

ActiveDocument.Sections["Limits Chart"].ShowLegend=true;

The JavaScript script to show a chart legend if chk_ShowLegend is true is:

if (chk_ShowLegend.Checked==true)
{
ActiveDocument.Sections["Limits Chart"].ShowLegend=true;
}
else
{
ActiveDocument.Sections["Limits Chart"].ShowLegend=false;
}

Caution!

Use one equal sign when assigning a value, use two equal signs when testing if the value matches true.

Tip:

The check box and its script show the chart legend when the check box is selected and its state becomes “checked.” Since the chart legend is already showing, the check box must be cleared to hide the legend the first time the Dashboard section is used. The initial state of the chart and the check box can be set with JavaScript statements associated with the OnActivate event of the Dashboard section:

ActiveDocument.Sections["Limits Chart"].ShowLegend=true;
chk_ShowLegend.Checked=true;

Tip:

Set both ShowLegend and the check box Checked properties to true when the section is activated.