Page 242 - Excel Progamming Weekend Crash Course
P. 242

n540629 ch17.qxd  9/2/03  9:35 AM  Page 217




                  Session 17 — Introduction to Charts                                    217

               Property              Description
               Top                   The distance in points from the top edge of the title to the top
                                     edge of the chart area
               Text                  The text of the title. By default this is blank.



                          For an example of adding a title to a chart, see Listing 17-3 later in this
                          session.
                 Cross-Ref


               Chart Axis Titles
               Most Excel charts have two axes (the pie chart is one exception). The horizontal axis is the
               category axis, and the vertical axis is the value axis. By default, neither axis is given a title,
               but you can add titles as required by your application.
                  A chart’s axes are referenced by means of the Chart object’s Axes collection. You identify
               which axis, value, or category you are referring to by using the constants xlCategory and
               xlValue. Thus, the code
                  SomeChart.Axes(xlCategory)
                  references the chart’s category axis, while

                  SomeChart.Axes(xlValue)

                  references its value axis. To add a title to an axis, set its HasTitle property to True;
               then use the AxisTitle.Text property to set the title. For example, assuming that ch
               refers to an existing chart:

                  ch.Axes(xlValue).HasTitle = True
                  ch.Axes(xlValue).AxisTitle.Text = “Sales by region”
                  To remove a title from an axis, set the HasTitle property to False. To modify an existing
               axis title, change the AxisTitle.Text property. (Changing the font of an axis title is cov-
               ered later in this session.)

                          Removing an axis title by setting HasTitle to False does not simply hide the
                          title, but destroys it. To later add a title, you must recreate it from scratch.
                   Tip

                          Be sure to set HasTitle to True before trying to work with the AxisTitle
                          object. If you do not, an error occurs.
                  Note
                  The program in Listing 17-3 is an improvement on the program presented earlier in this
               session. It creates a chart from the worksheet data presented earlier (see Figure 17-3), with
               the addition of a chart title and axis titles on both the value and category axes. The result-
               ing chart is shown in Figure 17-6.
   237   238   239   240   241   242   243   244   245   246   247