我的模板Excel文件有一个具体的工作表,包含4个图表,扭矩,速度,功率,温度。
Sheets("Graphs").Select
ActiveSheet.ChartObjects("Chart 1").Activate
Set My_Active_Chart = AvtiveSheet.ChartObject(1)
Set Range_X = Range(Cells(3, 2), Cells(Last_Row, 2))
ActiveChart.ChartType = xlLine
My_Active_Chart.Chart.SetSourceData Source:=ActiveWorkbook.Sheets("CAN Data")
For X = 1 To Torque_Col_Size
Set Range_Y = Range(Cells(3, Torque_Col(1, X)), Cells(Last_Row, Torque_Col(1, X)))
ActiveCahrt.SeriesCollection.Add Source:=ActiveWorkbook.Sheets("CAN Data").Range_Y
ActiveChart.SeriesCollection(1).XValues = Range_X
Next X
With ActiveChart
.HasTitle = True
ChartTitle = "CAN Torque Data"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Time (s)"
.Axes(xlCatagory, xlPrimary).HasTitle = True
.Axes(xlCatagory, xlPrimary).AxisTitle.Characters.Text = "Torque (Nm)"
End With
但是,我在指定数据范围方面有一些问题,这需要是动态的,因为数据量几乎每次都会发生变化。
Last_Row
变量。
谢谢你的帮助。