x | q | w | e | r | t | y |
y | 52 | 15 | 20 | 18 | 13 | 9 |
hi | 30 | 35 | 33 | 31 | 20 | 15 |
Sub test()
Set sht1 = ThisWorkbook.Worksheets("示例")
x = sht1.Range("I1").Left
y = sht1.Range("I1").Top
w = sht1.Range("N15").Width * 15
h = sht1.Range("N15").Height * 25
Set ch1 = sht1.ChartObjects.Add(x, y, w, h)
'chart方法
ch1.Chart.SetSourceData Source:=sht1.Range("A2:G4")
ch1.Chart.SetElement (msoElementDataLabelOutSideEnd)
ch1.Chart.SetElement (msoElementChartTitleNone)
ch1.Chart.SetElement (msoElementLegendTop)
'chart属性
ch1.Chart.ChartType = xlLineMarkers
Set line1 = ch1.Chart.SeriesCollection("y")
'设置其中的一条线
With line1
.MarkerStyle = xlMarkerStyleCircle
.MarkerSize = 7
End With
With line1.Format.Line '设置线条颜色
.Visible = msoTrue
.ForeColor.RGB = RGB(255, 0, 0) '红色
.DashStyle = msoLineDash
.Weight = 3
End With
'设置标记线颜色及填充色
line1.MarkerForegroundColor = RGB(0, 255, 0) '标记线颜色
line1.MarkerBackgroundColor = RGB(0, 0, 0) '填充色
End Sub
参考链接
VBA与Excel进阶系列-02-图表(中篇)_vba 折线图-CSDN博客https://blog.csdn.net/zishendianxia/article/details/76358423?spm=1001.2014.3001.5506
特此记录
anlog
2024年8月12日