本文介绍了VBA箱图和晶须图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动绘制箱形图和晶须图.下面的代码可以编译并运行,但错误栏不会出现在图表中.

I'm trying to automate plotting of a box and whiskers chart. The code below compiles and runs but the error bars do not appear in the chart.

Dim ws As Worksheet
Dim datarange As Range
Dim chtChart As Chart
Dim objChrt As ChartObject

Set ws = Sheets("sheet1")
Set datarange = ws.Range("F8:G10")

Set chtChart = Charts.add

With chtChart

  chtChart.ChartType = xlColumnStacked
  chtChart.SetSourceData Source:=datarange, PlotBy:=xlColumns

  With .Axes(xlCategory, xlPrimary)
        .CategoryNames = ws.Range("A2:A13")
        .TickLabels.Font.Bold = True
  End With
      .SeriesCollection(1).Format.Fill.Visible = msoFalse
      .SeriesCollection(2).Format.Fill.Visible = msoTrue


    Dim Sec1 As Series
    Set Sec1 = .SeriesCollection.NewSeries
    .SeriesCollection(3).HasErrorBars = True
    .SeriesCollection(3).ErrorBars.EndStyle = xlCap
    .SeriesCollection(3).ErrorBars.Format.Line.Visible = msoTrue
    .SeriesCollection(3).ErrorBars.Format.Line.ForeColor.RGB = RGB(0, 0, 0)
    .SeriesCollection(3).ErrorBars.Format.Line.Transparency = 0
    .SeriesCollection(3).ErrorBars.Format.Line.Weight = 1.5
    .SeriesCollection(3).ErrorBar Direction:=xlX, Include:=xlErrorBarIncludeBoth, Type:=xlErrorBarTypeCustom, Amount:="=CHART!F12:G12", MinusValues:="=CHART!F12:G12"

推荐答案

已解决.

    .SeriesCollection(3).values= <data range for whisker length>

type变体,用于绘制晶须所需的数据值重要说明:这将覆盖系列集合值(在这种情况下为seriescollection(3))晶须绘制后可以替换值

type variant, data values required to plot whiskersIMPORTANT: this overwrites the series collection values (seriescollection(3) in this case)values can be replaced after plotting whiskers

这篇关于VBA箱图和晶须图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 03:26