Customize The Chart Axis

You customize each axis on your chart with the Axis object properties and methods. Most charts that you create have a default of two different axes, the category axis and the values axis. For example, if you look at a standard column chart, the category axis runs horizontally across the bottom of the chart while the values axis runs vertically on the left side of the chart. When dealing with 3-D charts, there is a third series axis.

Each chart axis is a separate Axis object. The Axes collection object contains all Axis objects for the chart. You can use the Axes method to access an individual chart Axis object. When you use the Axes method, specify a value for the Type parameter indicating the axis that you want to remove. Specify one of the XlAxisType constants to indicate the axis type for this parameter. You can specify xlValue for the value axis, xlCategory for the category axis, or xlSeriesAxis for the third axis on the 3-D chart.

You can customize each axis using the AxisTitle, Border, Gridlines, DisplayUnitLabel, and TickLabels child objects. Each of these objects have additional child objects and corresponding properties and methods. The AxisTitle object represents the title that Excel adds to the corresponding axis. You can specify the text that displays for the axis title with the Caption property. You can customize the appearance of the axis title by calling the Font object properties. See the section "Format Chart Text" for more information on working with the Font object on a chart.

You set the HasTitle property to True to specify that the axis has a title. You can also customize the other objects in a similar fashion. For example, the Border object represents the axis border along the chart. You can use the Color property to change the color of that axis.

CUSTOMIZE THE CHART AXIS

CUSTOMIZE THE CHART AXIS

_D Create a new subroutine.

L"H Type Set SelectChart = ThisWorkbook.Charts(1), replacing

ThisWorkbook.Charts (1) with the chart reference.

Type .AxisTitle.Text = "Value Axis", replacing "Value Axis" with the axis title.

_D Create a new subroutine.

L0 Type Dim SelectChart As Chart, replacing SelectChart with the chart variable.

L"H Type Set SelectChart = ThisWorkbook.Charts(1), replacing

ThisWorkbook.Charts (1) with the chart reference.

-Q Type With SelectChart.Axes(xlValue), replacing xlValue with the axis constant value.

ype .HasTitle = True.

Type .AxisTitle.Text = "Value Axis", replacing "Value Axis" with the axis title.

WORKING WITH CHARTS

fed ra | You can add gridlines on a chart so that a user can determine a value at a specific point. Gridlines run either horizontally or vertically from the corresponding axis and extend the tick marks. You can use the Gridlines object to customize the gridline settings for a particular axis by adding both major and minor gridlines. A major gridline appears at each label on the axis and minor gridlines appear at even intervals between the major gridlines. The following code illustrates how to use the HasMajorGridlines property to turn on the gridlines and how to customize the appearance of the gridlines with the MajorGridlines property. Notice that the code customizes the appearance of the gridlines for the specified axis by utilizing the Border object. You can use the following properties with the Border object: Color, ColorIndex, LineStyle, Parent, and Weight.

Example:

With Charts(1).Axes(.xlValue)

.HasMajorGridlines = True

.MajorGridlines.Border.Color = RGB(0.255,0) .MajorGridlines.Border.LineStyle = xlDot .MajorGridlines.Border.Weight = xlThin End With

Excel Xldash

_Q Type .HasMajorGridlines = True.

_• Type .MajorGridlines. Border.LineStyle = xlDash, replacing xlDash with the xlLineStyle constant value.

_Q Type .HasMajorGridlines = True.

_O Type .MajorGridlines. Border.Color = RGB(0, 0, 255), replacing (0, 0, 255) with the color reference.

_• Type .MajorGridlines. Border.LineStyle = xlDash, replacing xlDash with the xlLineStyle constant value.

Note: See Appendix A for the xlLineStyle values.

LE Type End With.

Switch to Excel and run L-■ Excel updates the the macro. specified axis.

0 0

Responses

  • Hagosa Dahlak
    How to personalise axis label excel vba?
    1 year ago
  • prima chubb
    How to customize axis title in excel?
    2 months ago
  • dennis
    How to show tick marks on x axis chart vba?
    9 days ago

Post a comment