Sub chart()
Dim i%, arr, arr1, mychart As chart
On Error Resume Next
If Sheet1.ChartObjects.Count > 0 Then Sheet1.ChartObjects.Delete
arr = Range("d2:g146")
Sheet1.ChartObjects.Add(ActiveCell.Left, ActiveCell.Top, 400, 150).chart
Set mychart = Sheet1.ChartObjects(1).chart
With mychart
.ChartType = xlXYScatterLinesNoMarkers
.HasLegend = False
.Axes(xlValue).MajorGridlines.Delete
.Axes(xlValue).Delete
With .Axes(xlCategory)
.MajorTickMark = xlNone
.TickLabelPosition = xlNone
.Format.Line.Weight = 2
End With
End With
For i = 1 To UBound(arr)
mychart.SeriesCollection.NewSeries
With mychart.SeriesCollection(i)
.XValues = "sheet1!$d$" & i + 2 & ":$e$" & i + 2
.Values = "sheet1!$f$" & i + 2 & ":$g$" & i + 2
If Cells(i + 2, 3) <= 90 Then
.Format.Line.ForeColor.RGB = RGB(0, 0, 255)
ElseIf Cells(i + 2, 3) <= 180 Then
.Format.Line.ForeColor.RGB = RGB(0, 0, 255)
ElseIf Cells(i + 2, 3) <= 270 Then
.Format.Line.ForeColor.RGB = RGB(0, 0, 255)
Else
.Format.Line.ForeColor.RGB = RGB(0, 0, 255)
End If
.Format.Line.EndArrowheadStyle = msoArrowheadWide
.Format.Line.EndArrowheadWidth = msoArrowheadNone
.Format.Line.Weight = 0.75
End With
Next i
End Sub
想询问若上方vba程式想加
1.图表标题‘’风向及风速‘’
2.y轴标题"风速(m/s)"
3.在图上加曲线及副座标轴、标题"温度",资料范围为U3~U146
另外想询问垂直格线可以只显示一条吗?(比如在X=72(X轴中间的位置)处显示垂直格线就
好),若可以的话要怎么加在此VBA语法中呢?