创建特定图表

时间:2015-09-15 20:02:03

标签: excel vba excel-vba charts

我想创建一个这样的图表:http://take.ms/BEie1

enter image description here

前两列是名称和序列号。

我必须将这两个放在X轴上,就像在图像中一样,Y轴用于百分比用法。

这是我最近的尝试:

Dim xRange As Range
Dim yRange As Range
Dim objCht As ChartObject

Set objCht = detailsh.ChartObjects.Add(Left:=detailsh.Columns("A").Left, Width:=350, Top:=detailsh.Rows(9).Top, Height:=210)
Set xRange = Range("I2:J9")
Set xRange = Range("L2:L9")

With objCht.Chart
    Set srs = .SeriesCollection.NewSeries
    With srs
        .name = detailsh.Range("B1")
        .Values = detailsh.Range("I2:I7")
        .XValues = detailsh.Range("L2:L7")
    End With
End With

1 个答案:

答案 0 :(得分:0)

我终于可以解决了:) 这是我的代码,也许它可以帮助其他任何人。

Dim sourcech As Chart
Set sourcech = Charts.Add
Set sourcech = sourcech.Location(Where:=xlLocationAsObject, name:="Details")

With sourcech
    .SetSourceData Source:=Sheets("Details").Range("l2:L9")
    .SeriesCollection(1).XValues = Sheets("Details").Range("I2:J9") 'here you can modify the X axes

End With