|
- Sub Test()
- Dim SH As Worksheet
- Dim objChart As Chart
- Dim rgSource As Range, rgLocal As Range
- Dim strAmount As String, strMinusValues As String
- Dim intID As Integer, arrColor As Variant
-
- Set SH = Sheets("Sheet4")
- Set rgSource = SH.Range("A2:D18") '数据区域
- strAmount = "{" & rgSource.Rows.Count - 1 & "}" '误差,正偏值
- strMinusValues = "{0}" '误差,负偏值
-
- Set rgLocal = SH.Range("G2") '图表左上角单元格
- Set objChart = SH.Shapes.AddChart.Chart
- objChart.ChartArea.Top = rgLocal.Top
- objChart.ChartArea.Left = rgLocal.Left
- objChart.ChartArea.Height = 320
- objChart.ChartArea.Width = 520
-
- objChart.SetSourceData rgSource, 2 '设置数源,以列为单元
- objChart.FullSeriesCollection(1).ChartType = xlLineMarkersStacked '第一系列 为折线
- objChart.FullSeriesCollection(2).ChartType = xlXYScatter '第二系列 为散点
- objChart.FullSeriesCollection(3).ChartType = xlXYScatter '第三系列 为散点
- objChart.FullSeriesCollection(2).AxisGroup = 1 '设置第二系列 为主坐标
- objChart.FullSeriesCollection(3).AxisGroup = 1 '设置第三系列 为主坐标
- objChart.HasLegend = False '隐藏图例
-
- '第二、三系列添加水平误差线,误差量为自定义
- arrColor = Array(0, 0, RGB(238, 201, 0), RGB(178, 34, 34))
- For intID = 2 To 3
- objChart.FullSeriesCollection(intID).ErrorBar Direction:=xlX, Include:=xlErrorBarIncludeBoth, _
- Type:=xlCustom, amount:=strAmount, minusvalues:=strMinusValues
- With objChart.FullSeriesCollection(intID).ErrorBars.Format.Line
- .Visible = msoTrue
- .Weight = 3
- .ForeColor.RGB = arrColor(intID)
- .Transparency = 0
- End With
- Next
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|