Using CreateShape and RemoveShape

You use the CreateShape method to add a shape to a dashboard; for example, a goal for football, and you use the RemoveShape method to remove the shape of the goal. To perform the physical adding and removing of the shape, configure two command buttons.

Note:

Modify the example to suit your requirements.

  To configure two command buttons:

  1. In Interactive Reporting Studio, use the dashboard from the Placing Objects procedure.

  2. Press Ctrl+D to enter Design mode.

  3. From Elements, expand Controls, and drag two command buttons onto the dashboard.

  4. Right-click CommandButton2, and select Properties.

  5. In Properties, enter a Name and Title.

    For example, type AddGoal as the Name, and Add a Goal as the Title.

  6. Repeat steps 4-5 for CommandButton3 with alternate data.

    For example, type DelGoal as the Name, and Delete the Goal as the Title.

  7. From Graphics, drag a rectangle onto the dashboard, right-click, and select Properties.

    The rectangle will be added or removed by the command buttons.

  8. In Properties, enter a Name.

    For example, type LeftGoal.

  9. Select Add a Goal, right-click, and select Scripts.

  10. In Script Editor, copy and paste this code, or modify to suit your requirements.

    var objRect = ActiveSection.Shapes.CreateShape(bqRectangle)
    objRect.Name = "LeftGoal"
    objRect.Placement.XOffset = Field.Placement.XOffset - 10
    objRect.Placement.YOffset = Field.Placement.YOffset - 10
    objRect.Placement.Width = Ball.Placement.Width - 60
    objRect.Placement.Height = Field.Placement.Height + 20
    objRect.Fill.Color = bqBlack
    
  11. Click OK to close Script Editor.

  12. Right-click Delete the Goal, and select Scripts.

  13. In Script Editor, copy and paste this code, or modify to suit your requirements.

    try{
       Shapes.RemoveShape("LeftGoal")
       
    }catch(e){} // no worries it does not exist
    
  14. Click OK to close Script Editor.

  15. Press Ctrl+D to exit Design mode, and save the dashboard.