How to Clear the Legend Information from a Graph Control (113997)



The information in this article applies to:

  • Microsoft Visual Basic Professional Edition for Windows 3.0

This article was previously published under Q113997

SUMMARY

The Graph Control is one of the most versatile of the custom controls included with Visual Basic Professional, but it is also complex and can be difficult to master. It is easy to add legends using the LegendText property, but removing legends is not at all intuitive. It is necessary to set the DataReset property to 5 to clear the legend information.

MORE INFORMATION

The following example demonstrates how switching a graph between different numbers of sets produces an anomalous result when the DataReset property is not used.

Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 is created by default.
  2. Add a graph control (Graph1) and 2 command buttons (Command1 and Command2) to Form1. Be sure to make the Graph control large enough to accommodate the legend
  3. Add the following code to the Command1_Click and Command2_Click event procedures of Form1:
       Sub Command1_Click ()
          ' Remove the apostrophe from following line to remove the legend:
          ' graph1.DataReset = 5
          graph1.ThisPoint = 1
          graph1.LegendText = "1992"
          graph1.ThisPoint = 2
          graph1.LegendText = ""
          graph1.NumSets = 1
          graph1.DrawMode = 2
       End Sub
    
       Sub Command2_Click ()
          graph1.LegendText = "1992"
          graph1.NumSets = 2
          graph1.ThisPoint = 2
          graph1.LegendText = "1993"
          graph1.DrawMode = 2
       End Sub
    						
  4. Run the application by choosing Start from the Run menu or by pressing the F5 key.
Click the Command1 and Command2 buttons back and forth several times and observe the result. You will see that the legend from the previous data was not completely deleted. Now remove the apostrophe from the second line of code in the Command1_Click event procedure and repeat the process. You will see that it is now deleted.

REFERENCES

This article is based on the following articles in the Microsoft Knowledge Base:

81999 BUG: Graph: AutoInc Increments ThisPoint Instead of ThisSet

82155 VB Graph Control: ThisPoint, ThisSet Reset to 1 at Run Time

96450 Set DrawMode to 2 Or 3 to Update Changes to Graph at Run Time


Modification Type:MinorLast Reviewed:1/9/2003
Keywords:KB113997