[問題] vba增加標題及座標軸標題

作者: fishman0612 (精靈)   2020-08-04 16:44:59
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語法中呢?
作者: soyoso (我是耀宗)   2020-08-04 17:28:00
1.圖表標題,with mychart內加,setelement(..charttitle...)、hastitle、charttitle.text2.y軸標題,with mychart內加,setelement(...primaryvalueaxistitle...)、hastitle(於axes(...).hastitle)、axistitle.text3.資料再加入數列內,該數列設為副座標軸axisgroup,副座標軸標題setelement(...secondaryvalueaxistitle...)、axes(...).axistitle.text只顯示一條,新增個數列(xy散佈圖),以誤差線
作者: fishman0612 (精靈)   2020-08-04 18:44:00
感謝S大,不好意思,因為我完全沒寫過vba,內文是現成的程式,想詢問讀取副座標軸的資料該如何加入此段程式中呢?感謝您的回覆!
作者: soyoso (我是耀宗)   2020-08-04 20:02:00
加入於迴圈結束後,newseries新增u3:u146這個範圍到數列,values就為"工作表1!u3:u146",接著axisgroup設為副座標軸;標題setelement(...secondaryvalueaxistitle...)、axes(...).axistitle.text

Links booklink

Contact Us: admin [ a t ] ucptt.com