【问题标题】:Microsoft.Office.Interop.PowerPoint Chart - with broken y-AxisMicrosoft.Office.Interop.PowerPoint 图表 - y 轴损坏
【发布时间】:2014-06-24 05:56:59
【问题描述】:

我们正在使用 Interop PowerPoint Chart 类型来生成如图所示的面积图。我们需要“破碎”的 y 轴。我们不想要条本身的中断 - 我们只需要 y 轴上的中断。但无法找到实现此目的的属性或方法。

这是一个 winforms 应用程序。真的很感激一些指针......

【问题讨论】:

  • 您可以尝试录制宏并查看生成的VBA代码。这通常会导致所需的 API。

标签: winforms powerpoint winforms-interop


【解决方案1】:

偶然发现了这个问题,我让我的好奇心占据了上风。 我从this site得到了它是如何完成的。

我正在使用来自上述网站的示例数据进行此演练。

步骤大致是这样的:

  1. 为数据分离分配切割值。使用截断值分隔数据(我以截断值 7,500,000 为例)

这是与示例的数据分离(上面是原始的,下面是分离的):

                May         June        July
    London      1,234,565   1,452,369   1,478,852
    Paris       2,363,645   34,568,876  5,562,413
    Madrid      32,645,254  3,211,654   5,857,421
    Brussels    5,914,753   5,544,221   3,620,015
    Lisbon      5,824,676   4,541,258   4,015,876
    Munich      2,501,478   6,325,698   4,569,872

                May         June        July        Column4     Column5     Column6
    London      1,234,565   1,452,369   1,478,852   0           0           0
    Paris       2,363,645   7,500,000   5,562,413   0           34,568,876  0
    Madrid      7,500,000   3,211,654   5,857,421   32,645,254  0           0
    Brussels    5,914,753   5,544,221   3,620,015   0           0           0
    Lisbon      5,824,676   4,541,258   4,015,876   0           0           0
    Munich      2,501,478   6,325,698   4,569,872   0           0           0
  1. Column4Column5Column6 分配到辅助轴。

    Dim c As Microsoft.Office.Interop.PowerPoint.Chart
    Dim sc As Microsoft.Office.Interop.PowerPoint.SeriesCollection = Nothing
    Dim sr As Microsoft.Office.Interop.PowerPoint.Series = Nothing
    
    sc = c.SeriesCollection
    For i = 4 To sc.Count
        sr = sc.SeriesCollection(i)
        sr.AxisGroup = Microsoft.Office.Interop.PowerPoint.XlAxisGroup.xlSecondary
    Next
    
  2. 更改主轴和次轴比例以适合,就好像图表是分开的一样。我将主轴刻度从 0 更改为 1.6e7,将辅助轴刻度从 -7.0e7 更改为 7.0e7。同时,以百万为单位更改显示单位,并删除所有网格线。

    Dim ax As Microsoft.Office.Interop.PowerPoint.Axes
    Dim axpri As Microsoft.Office.Interop.PowerPoint.Axis
    Dim axsec As Microsoft.Office.Interop.PowerPoint.Axis
    
    ax = c.Axes
    axpri = ax.Item(Microsoft.Office.Interop.PowerPoint.XlAxisType.xlValue, _
                    Microsoft.Office.Interop.PowerPoint.XlAxisGroup.xlPrimary)
    axsec = ax.Item(Microsoft.Office.Interop.PowerPoint.XlAxisType.xlValue, _
                    Microsoft.Office.Interop.PowerPoint.XlAxisGroup.xlSecondary)
    axpri.MinimumScale = 0
    axpri.MaximumScale = 1.6e7
    axpri.DisplayUnit = Microsoft.Office.Interop.PowerPoint.XlDisplayUnit.xlMillions
    axpri.HasMajorGridlines = False
    axpri.HasMinorGridlines = False
    
    axsec.MinimumScale = -7.0e7
    axsec.MaximumScale = 7.0e7
    axsec.DisplayUnit = Microsoft.Office.Interop.PowerPoint.XlDisplayUnit.xlMillions
    axsec.HasMajorGridlines = False
    axsec.HasMinorGridlines = False
    
  3. 更改主轴和次轴编号格式,以便每个轴仅显示其自己的预期值。超过8M的主轴不会显示,小于30M的次轴不会显示。

    axpri.TickLabels.NumberFormat = "[<=8]0;;;"
    axsec.TickLabels.NumberFormat = "[>=30]0;;;"
    
  4. 重新着色次轴中的系列以匹配主轴中的系列。

    Dim srPrev As Microsoft.Office.Interop.PowerPoint.Series = Nothing
    
    For i = 4 To sc.Count
        sr = sc.SeriesCollection(i)
        srPrev = sc.SeriesCollection(i - 3)
        sr.Format.Fill.ForeColor.RGB = srPrev.Format.Fill.ForeColor.RGB
    Next
    
  5. 删除 Column4Column5Column6 的图例以获得无缝图表图例。

    c.Legend.LegendEntries(4).Delete()
    c.Legend.LegendEntries(5).Delete()
    c.Legend.LegendEntries(6).Delete()
    
  6. [可选] 为超过截断值的数据点添加整洁的颜色渐变。

    Dim p As Microsoft.Office.Interop.PowerPoint.Point = Nothing
    
    p = c.SeriesCollection("June").Points("Paris")
    p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
    p.Format.Fill.GradientAngle = 270
    p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.8)
    p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.97)
    
    p = c.SeriesCollection("May").Points("Madrid")
    p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
    p.Format.Fill.GradientAngle = 270
    p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.8)
    p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.97)
    
    p = c.SeriesCollection("Column5").Points("Paris")
    p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
    p.Format.Fill.GradientAngle = 90
    p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.7)
    p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.95)
    
    p = c.SeriesCollection("Column4").Points("Madrid")
    p.Format.Fill.TwoColorGradient(Microsoft.Office.Core.MsoGradientStyle.msoGradientHorizontal, 1)
    p.Format.Fill.GradientAngle = 90
    p.Format.Fill.GradientStops.Insert(p.Format.Fill.ForeColor.RGB, 0.7)
    p.Format.Fill.GradientStops.Insert(p.Format.Fill.BackColor.RGB, 0.95)
    
  7. 瞧!努力有回报,PowerPoint 图表中的 y 轴损坏。

【讨论】:

    猜你喜欢
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 2019-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多