辅助轴的标题不会通过vba出现在图表上

时间:2013-10-29 15:14:12

标签: excel vba charts

我是VBA的新手,我制作的图表需要有两个y轴并共享相同的x轴。我不太确定xlvalue和xlcategory的整个概念以及如何使用它们,我在网上使用了一些例子,但我无法使它工作。我在下面粘贴了我的代码。在此先感谢!!

With Totalchart.Axes(xlCategory)
    .HasTitle = True
    .HasTitle = True
    .HasMajorGridlines = True
    .HasMinorGridlines = True
    With .AxisTitle
        .Caption = "Time (min)"
        .Font.Name = "bookman"
        .Font.Size = 10
    End With
End With

With Totalchart.Axes(xlValue)
    '.CategoryType = xlAutomatic
    .HasTitle = True
    .HasTitle = True
    .HasMajorGridlines = True
    .HasMinorGridlines = True
    .MinimumScale = 0
    With .AxisTitle
        .Caption = "caption1"
        .Font.Name = "bookman"
        .Font.Size = 10
    End With
End With

With Totalchart.Axes(xlValue, xlSecondary)
    '.CategoryType = xlAutomatic
    .HasTitle = True
    .HasTitle = True
    .MinimumScale = 0
    With .AxisTitle
        .Caption = "Caption2"
        .Font.Name = "bookman"
        .Font.Size = 10
    End With
End With

1 个答案:

答案 0 :(得分:0)

.AxisTitle.Text.AxisTitle.Caption略有不同。见MSDN Documention

在Excel 2007中,将.AxisTitle.Text设置为轴标题,如下所示:

With Totalchart.Axes(xlValue, xlSecondary)
    .HasTitle = True
    .MinimumScale = 0
    With .AxisTitle
        .Text = "Axis Title"
        .Font.Name = "bookman"
        .Font.Size = 10
    End With
End With

确保在此代码之前启用了辅助轴。这样的事情取决于你的系列集。

With Totalchart
  .SeriesCollection(2).AxisGroup = xlSecondary
  .HasAxis(xlValue, xlSecondary) = True
  .Axes(xlCategory, xlSecondary).CategoryType = xlAutomatic
End With

另外,尝试录制自己的宏,手动创建辅助轴并调查代码。可能有助于您的命名。