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").Lefty = sht1.Range("I1").Topw = sht1.Range("N15").Width * 15h = sht1.Range("N15").Height * 25Set 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 = xlLineMarkersSet line1 = ch1.Chart.SeriesCollection("y")'设置其中的一条线With line1.MarkerStyle = xlMarkerStyleCircle.MarkerSize = 7End WithWith line1.Format.Line '设置线条颜色.Visible = msoTrue.ForeColor.RGB = RGB(255, 0, 0) '红色.DashStyle = msoLineDash.Weight = 3End 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日