vb mschart的问题
OptionExplicitDimintCAsIntegerDimdblStepAsDoubleDimp,i,num,pl,lAsIntegerPrivateConstP...
Option Explicit
Dim intC As Integer
Dim dblStep As Double
Dim p, i, num, pl, l As Integer
Private Const Pi = 3.1415926
Dim MyData(360, 2) As Variant
Private Sub Form_Load()
With MSChart1
.TitleText = "电压时间 V/Hours"
' '设置图线的外观 画笔宽度,类型
.Plot.SeriesCollection(1).Pen.Width = 20
.Plot.SeriesCollection(1).Pen.Style = VtPenStyleSolid
' '设置XY轴,自动缩放为false
.Plot.Axis(VtChAxisIdX).ValueScale.Auto = False
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
'// 设置最大值
.Plot.Axis(VtChAxisIdX).ValueScale.Maximum = 360
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 300
'// 设置最小值
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
.Plot.Axis(VtChAxisIdX).ValueScale.Minimum = 0
'//
.Plot.Axis(VtChAxisIdX).ValueScale.MajorDivision = 10 'X轴主要网格数量
.Plot.Axis(VtChAxisIdY).ValueScale.MajorDivision = 10 'Y轴主要网格数量
.Plot.Axis(VtChAxisIdX).ValueScale.MinorDivision = 0 'X轴次要网格数量
.Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 0 'Y轴次要网格数量
' .Plot.Axis(VtChAxisIdX).AxisGrid.MajorPen.Style = VtPenStyleDotted
' .Plot.Axis(VtChAxisIdY).AxisGrid.MajorPen.Style = VtPenStyleDotted
MSChart1.Plot.AutoLayout = False '坐标布局人工还是自动
MSChart1.Plot.UniformAxis = False '坐标单位刻度是否一致
MSChart1.chartType = VtChChartType2dXY '设置图形为二维散点图
MSChart1.ChartData = MyData '数据
End With
dblStep = 8 * Pi / 360
For i = 0 To 360
MyData(i, 0) = i '-----x轴坐标值--
MyData(i, 1) = 149 * Sin(dblStep * i) + 150 '---Y轴坐标值----------
Next i
End Sub
以上为一段程序,我想用他画出正玄曲线,结果如图,为什么呀、求修改,如何能出来正玄图。 展开
Dim intC As Integer
Dim dblStep As Double
Dim p, i, num, pl, l As Integer
Private Const Pi = 3.1415926
Dim MyData(360, 2) As Variant
Private Sub Form_Load()
With MSChart1
.TitleText = "电压时间 V/Hours"
' '设置图线的外观 画笔宽度,类型
.Plot.SeriesCollection(1).Pen.Width = 20
.Plot.SeriesCollection(1).Pen.Style = VtPenStyleSolid
' '设置XY轴,自动缩放为false
.Plot.Axis(VtChAxisIdX).ValueScale.Auto = False
.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
'// 设置最大值
.Plot.Axis(VtChAxisIdX).ValueScale.Maximum = 360
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 300
'// 设置最小值
.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0
.Plot.Axis(VtChAxisIdX).ValueScale.Minimum = 0
'//
.Plot.Axis(VtChAxisIdX).ValueScale.MajorDivision = 10 'X轴主要网格数量
.Plot.Axis(VtChAxisIdY).ValueScale.MajorDivision = 10 'Y轴主要网格数量
.Plot.Axis(VtChAxisIdX).ValueScale.MinorDivision = 0 'X轴次要网格数量
.Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 0 'Y轴次要网格数量
' .Plot.Axis(VtChAxisIdX).AxisGrid.MajorPen.Style = VtPenStyleDotted
' .Plot.Axis(VtChAxisIdY).AxisGrid.MajorPen.Style = VtPenStyleDotted
MSChart1.Plot.AutoLayout = False '坐标布局人工还是自动
MSChart1.Plot.UniformAxis = False '坐标单位刻度是否一致
MSChart1.chartType = VtChChartType2dXY '设置图形为二维散点图
MSChart1.ChartData = MyData '数据
End With
dblStep = 8 * Pi / 360
For i = 0 To 360
MyData(i, 0) = i '-----x轴坐标值--
MyData(i, 1) = 149 * Sin(dblStep * i) + 150 '---Y轴坐标值----------
Next i
End Sub
以上为一段程序,我想用他画出正玄曲线,结果如图,为什么呀、求修改,如何能出来正玄图。 展开
展开全部
别用控件了,用我的这段代码吧
直接粘贴到窗体上运行即可,不用任何控件就可以绘图
可以绘制任何直角坐标系的曲线图,不需要控件,也可以调整坐标的位置
Option Explicit
Private Const X_Axe = 0.5 'X轴原点位于窗口的水平位置比例
Private Const Y_Axe = 0.6 'Y轴原点位于窗口的垂直位置比例
Private Const ScaleRate = 30 '多少像素代表一个单位长度
Private Const DrawColor = vbRed '曲线颜色
Private ErrExp As Boolean '当表达式发生错误时,会置True(比如函数在此点无有效值)
Private Sub Form_Load()
Me.Show
Me.Cls
Call DrawAxe
Call DrawCoordinate
End Sub
Private Function Expression(ByVal X As Double) As Double '公式函数可以是任意内容
ErrExp = False '进入时,必须重置此标志为False
Expression = Sin(X)
' If X > 0 Then '这里代码任意,也可以是Expression = 2 * X ^ 2 + 2 * X + 1之类的
' Expression = Log(X)
' Else
' Expression = 0
' ErrExp = True
' End If
End Function
Private Sub DrawCoordinate() '绘制曲线过程
Dim i As Long
Dim Last(1 To 2) As Long, This(1 To 2) As Long
Dim X_offset As Long
Dim Y_offset As Long
Me.ScaleMode = vbPixels
X_offset = Me.ScaleWidth * X_Axe
Y_offset = Me.ScaleHeight * Y_Axe
'设置一个初始值
Last(1) = 0
Last(2) = -Expression((0 - X_offset) / ScaleRate) * ScaleRate
i = 0
While i <= Me.ScaleWidth
'取下一点的值
This(1) = i
This(2) = -Expression((i - X_offset) / ScaleRate) * ScaleRate
'判断表达式是否出错
If ErrExp = True Then
'出错的情况下,循环直到没有错误或者超出范围为止
While ErrExp = True And i <= Me.ScaleWidth
i = i + 1
This(1) = i
This(2) = -Expression((i - X_offset) / ScaleRate) * ScaleRate
Wend
'重置起点
Last(1) = This(1)
Last(2) = This(2)
End If
'画线
Me.Line (Last(1), Last(2) + Y_offset)-(This(1), This(2) + Y_offset), DrawColor
Last(1) = This(1)
Last(2) = This(2)
i = i + 1
Wend
End Sub
Private Sub DrawAxe() '绘制坐标的过程
Dim X_offset As Long
Dim Y_offset As Long
Dim i As Long
Me.ScaleMode = vbPixels '取单位长度为像素
X_offset = Me.ScaleWidth * X_Axe '计算坐标轴轴位置
Y_offset = Me.ScaleHeight * Y_Axe
'绘制坐标轴
Me.Line (X_offset, 0)-(X_offset, Me.ScaleHeight)
Me.Line (0, Y_offset)-(Me.ScaleWidth, Y_offset)
'绘制坐标线
For i = X_offset + ScaleRate To Me.ScaleWidth Step ScaleRate
Me.Line (i, 0)-(i, Me.ScaleHeight), vbWhite
Next i
For i = X_offset - ScaleRate To 0 Step -ScaleRate
Me.Line (i, 0)-(i, Me.ScaleHeight), vbWhite
Next i
For i = Y_offset + ScaleRate To Me.ScaleHeight Step ScaleRate
Me.Line (0, i)-(Me.ScaleWidth, i), vbWhite
Next i
For i = Y_offset - ScaleRate To 0 Step -ScaleRate
Me.Line (0, i)-(Me.ScaleWidth, i), vbWhite
Next i
End Sub
Private Sub Form_Paint()
Call Form_Resize
End Sub
Private Sub Form_Resize()
Me.Cls
Call DrawAxe
Call DrawCoordinate
End Sub
直接粘贴到窗体上运行即可,不用任何控件就可以绘图
可以绘制任何直角坐标系的曲线图,不需要控件,也可以调整坐标的位置
Option Explicit
Private Const X_Axe = 0.5 'X轴原点位于窗口的水平位置比例
Private Const Y_Axe = 0.6 'Y轴原点位于窗口的垂直位置比例
Private Const ScaleRate = 30 '多少像素代表一个单位长度
Private Const DrawColor = vbRed '曲线颜色
Private ErrExp As Boolean '当表达式发生错误时,会置True(比如函数在此点无有效值)
Private Sub Form_Load()
Me.Show
Me.Cls
Call DrawAxe
Call DrawCoordinate
End Sub
Private Function Expression(ByVal X As Double) As Double '公式函数可以是任意内容
ErrExp = False '进入时,必须重置此标志为False
Expression = Sin(X)
' If X > 0 Then '这里代码任意,也可以是Expression = 2 * X ^ 2 + 2 * X + 1之类的
' Expression = Log(X)
' Else
' Expression = 0
' ErrExp = True
' End If
End Function
Private Sub DrawCoordinate() '绘制曲线过程
Dim i As Long
Dim Last(1 To 2) As Long, This(1 To 2) As Long
Dim X_offset As Long
Dim Y_offset As Long
Me.ScaleMode = vbPixels
X_offset = Me.ScaleWidth * X_Axe
Y_offset = Me.ScaleHeight * Y_Axe
'设置一个初始值
Last(1) = 0
Last(2) = -Expression((0 - X_offset) / ScaleRate) * ScaleRate
i = 0
While i <= Me.ScaleWidth
'取下一点的值
This(1) = i
This(2) = -Expression((i - X_offset) / ScaleRate) * ScaleRate
'判断表达式是否出错
If ErrExp = True Then
'出错的情况下,循环直到没有错误或者超出范围为止
While ErrExp = True And i <= Me.ScaleWidth
i = i + 1
This(1) = i
This(2) = -Expression((i - X_offset) / ScaleRate) * ScaleRate
Wend
'重置起点
Last(1) = This(1)
Last(2) = This(2)
End If
'画线
Me.Line (Last(1), Last(2) + Y_offset)-(This(1), This(2) + Y_offset), DrawColor
Last(1) = This(1)
Last(2) = This(2)
i = i + 1
Wend
End Sub
Private Sub DrawAxe() '绘制坐标的过程
Dim X_offset As Long
Dim Y_offset As Long
Dim i As Long
Me.ScaleMode = vbPixels '取单位长度为像素
X_offset = Me.ScaleWidth * X_Axe '计算坐标轴轴位置
Y_offset = Me.ScaleHeight * Y_Axe
'绘制坐标轴
Me.Line (X_offset, 0)-(X_offset, Me.ScaleHeight)
Me.Line (0, Y_offset)-(Me.ScaleWidth, Y_offset)
'绘制坐标线
For i = X_offset + ScaleRate To Me.ScaleWidth Step ScaleRate
Me.Line (i, 0)-(i, Me.ScaleHeight), vbWhite
Next i
For i = X_offset - ScaleRate To 0 Step -ScaleRate
Me.Line (i, 0)-(i, Me.ScaleHeight), vbWhite
Next i
For i = Y_offset + ScaleRate To Me.ScaleHeight Step ScaleRate
Me.Line (0, i)-(Me.ScaleWidth, i), vbWhite
Next i
For i = Y_offset - ScaleRate To 0 Step -ScaleRate
Me.Line (0, i)-(Me.ScaleWidth, i), vbWhite
Next i
End Sub
Private Sub Form_Paint()
Call Form_Resize
End Sub
Private Sub Form_Resize()
Me.Cls
Call DrawAxe
Call DrawCoordinate
End Sub
展开全部
将MSChart1.ChartData = MyData '数据
放到for循环后面就好了
最后部分应该是
For i = 0 To 360
MyData(i, 0) = i '-----x轴坐标值--
MyData(i, 1) = 149 * Sin(dblStep * i) + 150 '---Y轴坐标值----------
Next i
MSChart1.ChartData = MyData '数据
放到for循环后面就好了
最后部分应该是
For i = 0 To 360
MyData(i, 0) = i '-----x轴坐标值--
MyData(i, 1) = 149 * Sin(dblStep * i) + 150 '---Y轴坐标值----------
Next i
MSChart1.ChartData = MyData '数据
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
哇,好难,我一点都不懂。我只是个初中生,而且是10届的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询