A = "A" & 2 & ":A" & N 'X坐标轴数据源
B = "C" & 2 & ":C" & N 'Y坐标轴数据源
xmin = Application.WorksheetFunction.Min(ws.Range(A)) 'X坐标轴最小值
xmax = Application.WorksheetFunction.Max(ws.Range(A)) 'X坐标轴最大值
ymin = Application.WorksheetFunction.Min(ws.Range(B)) 'Y坐标轴最小值
ymax = Application.WorksheetFunction.Max(ws.Range(B)) 'Y坐标轴最大值
' Set myRange = ws.Range("A" & 2 & ":A" & N, "C" & 2 & ";C" & N) '图表的数据源
Set myRange = ws.Range(A, B) '图表的数据源 Set myChart = ws.ChartObjects.Add(100, 300, 600, 500) '创建一个新图表
With myChart.Chart
.ChartType = xlXYScatterLinesNoMarkers '指定图表类型
.SetSourceData Source:=myRange, PlotBy:=xlColumns '指定图表数据源和绘图方式
.HasTitle = True '有标题
.ChartTitle.Text = "加速度时程"
With .ChartTitle.Font '设置标题的字体
.Size = 16
.ColorIndex = 3
.Name = "华文新魏"
End With
.Axes(xlCategory, xlPrimary).HasTitle = True 'X坐标轴有图表标题
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = " 时间(s)"
.Axes(xlValue, xlPrimary).HasTitle = True 'Y坐标轴有图表标题
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "地表加速度(m/s2)"
With .Axes(xlCategory)
.MinimumScale = xmin 'X坐标轴最小刻度
.MaximumScale = xmax 'X坐标轴最大刻度
End With
With .Axes(xlValue)
.MinimumScale = ymin 'Y坐标轴最小刻度
.MaximumScale = ymax 'Y坐标轴最 大刻度
End With
With .ChartArea.Interior '设置图色表区的颜
.ColorIndex = 15
.PatternColorIndex = 1
.Pattern = xlSolid
End With
With .PlotArea.Interior '设置绘图区的颜色
.ColorIndex = 35
.PatternColorIndex = 1
.Pattern = xlSolid
End With
With .SeriesCollection(1)
With .Border '设置第一个数据系列的格式
' .ColorIndex = 3
'.Weight = xlThin
'.LineStyle = xlDot
End With
' .MarkerStyle = xlCircle
' .Smooth = True
' .MarkerSize = 5
End With
.Legend.Delete '删除图例
我想要只利用A列和C列绘图但是绘图中利用这段代码却绘出了A列和B列以及A列和C列两条曲线,麻烦高手指导一下,这是什么原因了,主要看一下Set myRange = ws.Range(A, B) '图表的数据源
这句代码有什么问题,该怎么去改,在此谢过。
B = "C" & 2 & ":C" & N 'Y坐标轴数据源
xmin = Application.WorksheetFunction.Min(ws.Range(A)) 'X坐标轴最小值
xmax = Application.WorksheetFunction.Max(ws.Range(A)) 'X坐标轴最大值
ymin = Application.WorksheetFunction.Min(ws.Range(B)) 'Y坐标轴最小值
ymax = Application.WorksheetFunction.Max(ws.Range(B)) 'Y坐标轴最大值
' Set myRange = ws.Range("A" & 2 & ":A" & N, "C" & 2 & ";C" & N) '图表的数据源
Set myRange = ws.Range(A, B) '图表的数据源 Set myChart = ws.ChartObjects.Add(100, 300, 600, 500) '创建一个新图表
With myChart.Chart
.ChartType = xlXYScatterLinesNoMarkers '指定图表类型
.SetSourceData Source:=myRange, PlotBy:=xlColumns '指定图表数据源和绘图方式
.HasTitle = True '有标题
.ChartTitle.Text = "加速度时程"
With .ChartTitle.Font '设置标题的字体
.Size = 16
.ColorIndex = 3
.Name = "华文新魏"
End With
.Axes(xlCategory, xlPrimary).HasTitle = True 'X坐标轴有图表标题
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = " 时间(s)"
.Axes(xlValue, xlPrimary).HasTitle = True 'Y坐标轴有图表标题
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "地表加速度(m/s2)"
With .Axes(xlCategory)
.MinimumScale = xmin 'X坐标轴最小刻度
.MaximumScale = xmax 'X坐标轴最大刻度
End With
With .Axes(xlValue)
.MinimumScale = ymin 'Y坐标轴最小刻度
.MaximumScale = ymax 'Y坐标轴最 大刻度
End With
With .ChartArea.Interior '设置图色表区的颜
.ColorIndex = 15
.PatternColorIndex = 1
.Pattern = xlSolid
End With
With .PlotArea.Interior '设置绘图区的颜色
.ColorIndex = 35
.PatternColorIndex = 1
.Pattern = xlSolid
End With
With .SeriesCollection(1)
With .Border '设置第一个数据系列的格式
' .ColorIndex = 3
'.Weight = xlThin
'.LineStyle = xlDot
End With
' .MarkerStyle = xlCircle
' .Smooth = True
' .MarkerSize = 5
End With
.Legend.Delete '删除图例
我想要只利用A列和C列绘图但是绘图中利用这段代码却绘出了A列和B列以及A列和C列两条曲线,麻烦高手指导一下,这是什么原因了,主要看一下Set myRange = ws.Range(A, B) '图表的数据源
这句代码有什么问题,该怎么去改,在此谢过。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货