|
图表的例子:
- Sub AddChart()
- Dim i%, Myr%, ht, tp, lf, wd, myChart, n%
- Sheet14.Activate
- Myr = Cells(Rows.Count, 7).End(xlUp).Row
- ht = [a1].Resize(15, 1).Height
- wd = [a1].Resize(1, 7).Width
- lf = [j1].Left
- For i = 1 To Cells(Myr, 7).Value Step 4
- n = n + 1
- tp = Cells(15 * n - 14, 1).Top
- Set myChart = ActiveSheet.ChartObjects.Add _
- (Left:=lf, Top:=tp, _
- Width:=wd, Height:=ht)
- '增加一个图表
- With myChart.Chart
- .ChartType = xlLine
- '设置图表类型为折线图
- .SetSourceData Source:=Range("H" & i + 1 & ":J" & i + 4), PlotBy:=xlColumns
- '设置图表的数据源
- .FullSeriesCollection(1).XValues = "='图形分析-4'!$H$" & i + 1 & ":$H$" & i + 4
- .FullSeriesCollection(1).Values = "='图形分析-4'!$I$" & i + 1 & ":$I$" & i + 4
- .FullSeriesCollection(2).Values = "='图形分析-4'!$J$" & i + 1 & ":$J$" & i + 4
- .Legend.Delete
- .Axes(xlValue).Format.Line.Visible = msoFalse
- '删除图例
- .SetElement (msoElementChartTitleAboveChart)
- '添加图表标题位于图表上方
- .ChartTitle.Text = Cells(i + 1, 7).Value
- '设置图表标题为对应组号
- End With
- Next
- End Sub
复制代码 |
|