Using Assignment versus Comparison Operators

JavaScript makes a distinction between assignment (=) and comparison (==) operators.

Example

Insert a new Dashboard section in Sample3.bqy. Add a line chart and two buttons titled Comparison and Assignment.

Add a JavaScript script to the Comparison button to compare the type of chart to bqChartTypeVerticalBar and open an alert that displays the result of the comparison. Test the comparison button. What does the alert say?

Script the Assignment button to change the chart type to bqChartTypePie. Try the comparison button again. What does the alert say now?

Figure 1. Assigning and Comparing chart type

Image shows "Comparison" and "Assigment" buttons for Revenue by Time chart.

Tip:

Both JavaScript scripts act on the actual chart, not the view of the chart in the Dashboard section.

The script for the Comparison button uses == to test if ChartType matches bqChartTypeVerticalBar. The alert displays true if they match, false if they don’t match.

The Assignment button’s script uses = to set RevByTime’s ChartType property equal to bqChartTypePie. The chart changes to a pie chart.