【问题标题】:Primary and Secondary axis VBA主轴和辅助轴 VBA
【发布时间】:2017-06-06 14:58:53
【问题描述】:

我正在尝试使用以下代码在一张图表上的主要轴和次轴上绘制两个时间序列:

   Set ARng_1 = range("Annual_Series_1")
   Set MRng_1 = range("Monthly_Series_1")
   Sheet10.ChartObjects("Chart 17").Activate
   With ActiveChart
  .ChartType = xlLineMarkers
  .SeriesCollection.Add Source:=ARng_1
  .SeriesCollection.Add Source:=MRng_1
  .Axes(xlCategory, xlPrimary).HasTitle = True
  .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dates"
  .SeriesCollection(1).Axes(xlValue, xlPrimary).HasTitle = True
  .SeriesCollection(2).Axes(xlValue, xlSecondary).HasTitle = True
  .SeriesCollection(1).Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Annual"
  .SeriesCollection(2).Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Monthly"
  .Axes(xlCategory).HasMajorGridlines = True
  .SeriesCollection(1).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
  .SeriesCollection(2).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
  .SeriesCollection(1).XValues = Date_Rng
  End With 

我不断收到错误消息(“对象不支持此属性或对象”):

  .SeriesCollection(1).Axes(xlValue, xlPrimary).HasTitle = True

我在这里做错了什么?另外,我是否正确对待轴?我这样做对吗?

谢谢!!!!!!

【问题讨论】:

  • SeriesCollection(1) 表示 Series 对象。您收到错误是因为 Series 对象没有 Axes 成员。您可以使用Chart.Axes 访问轴。您可以使用Series.AxisGroup 为系列设置主轴和次轴。
  • 感谢您的帮助!

标签: excel vba plot


【解决方案1】:

我认为您的代码如下所示..

   Set ARng_1 = Range("Annual_Series_1")
   Set MRng_1 = Range("Monthly_Series_1")



      With ActiveChart
        For i = .SeriesCollection.Count To 1 Step -1
              .SeriesCollection(i).Delete
        Next i
        .ChartType = xlLineMarkers
        .SeriesCollection.Add Source:=ARng_1
        .SeriesCollection.Add Source:=MRng_1
        .SeriesCollection(2).AxisGroup = 2
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Dates"
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlSecondary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Annual"
        .Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "Monthly"
        .Axes(xlCategory).HasMajorGridlines = True
        .SeriesCollection(1).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
        .SeriesCollection(2).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
        .SeriesCollection(1).XValues = date_rng
      End With

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多