VB6 里MSCHART 画两条曲线.docx
VB6 里MSCHART 画两条曲线一条曲线的代码如下 : Dim MyData(12, 1) As Double '-x轴坐标值-Y轴坐标值- MyData(0, 0) = 0: MyData(0, 1) = 180 '本句代表了:第一点数据的X轴坐标为0,Y轴坐标为180 MyData(1, 0) = 1: MyData(1, 1) = 960 MyData(2, 0) = 2: MyData(2, 1) = 60 MyData(3, 0) = 3: MyData(3, 1) = 0 MyData(4, 0) = 4: MyData(4, 1) = 0 MyData(5, 0) = 5: MyData(5, 1) = 60 MyData(6, 0) = 6: MyData(6, 1) = 60 MyData(7, 0) = 7: MyData(7, 1) = 0 MyData(8, 0) = 8: MyData(8, 1) = 60 MyData(9, 0) = 9: MyData(9, 1) = 60 MyData(10, 0) = 10: MyData(10, 1) = 0 MyData(11, 0) = 11: MyData(11, 1) = 0 MyData(12, 0) = 12: MyData(12, 1) = 60 '波形图外观设置 With MSChart1 .TitleText = "值" ' '设置图线的外观 .Plot.SeriesCollection(1).Pen.Width = 30 .Plot.SeriesCollection(1).Pen.Style = VtPenStyleSolid ' '设置XY轴 .Plot.Axis(VtChAxisIdX).ValueScale.Auto = False .Plot.Axis(VtChAxisIdY).ValueScale.Auto = False '/ 设置最大值 .Plot.Axis(VtChAxisIdX).ValueScale.Maximum = 12 .Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 1000 '/ 设置最小值 .Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0 .Plot.Axis(VtChAxisIdX).ValueScale.Minimum = 0 '/ .Plot.Axis(VtChAxisIdX).ValueScale.MajorDivision = 12 '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 我想再添加一条蓝色的 谁能给下代码!急! 代码如下所示。用!开头的注释是我加入的主要解释。实现所需效果。 Dim MyData(12, 2) As Double '!加入1维就是增加一条线 '-x轴坐标值-Y轴坐标值- MyData(0, 0) = 0: MyData(0, 1) = 180 '本句代表了:第一点数据的X轴坐标为0,Y轴坐标为180 MyData(1, 0) = 1: MyData(1, 1) = 960 MyData(2, 0) = 2: MyData(2, 1) = 60 MyData(3, 0) = 3: MyData(3, 1) = 0 MyData(4, 0) = 4: MyData(4, 1) = 0 MyData(5, 0) = 5: MyData(5, 1) = 60 MyData(6, 0) = 6: MyData(6, 1) = 60 MyData(7, 0) = 7: MyData(7, 1) = 0 MyData(8, 0) = 8: MyData(8, 1) = 60 MyData(9, 0) = 9: MyData(9, 1) = 60 MyData(10, 0) = 10: MyData(10, 1) = 0 MyData(11, 0) = 11: MyData(11, 1) = 0 MyData(12, 0) = 12: MyData(12, 1) = 60 '!为新加入的一条线赋值 Dim i As Integer For i = 0 To 12 MyData(i, 2) = 0.3 * MyData(i, 1) Next '波形图外观设置 With MSChart1 .TitleText = "值" ' '设置图线的外观 .Plot.SeriesCollection(1).Pen.Width = 30 .Plot.SeriesCollection(1).Pen.Style = VtPenStyleSolid '!设置第二条线的外观 .Plot.SeriesCollection(2).Pen.Width = 30 .Plot.SeriesCollection(2).Pen.Style = VtPenStyleSolid ' '设置XY轴 .Plot.Axis(VtChAxisIdX).ValueScale.Auto = False .Plot.Axis(VtChAxisIdY).ValueScale.Auto = False '/ 设置最大值 .Plot.Axis(VtChAxisIdX).ValueScale.Maximum = 12 .Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 1000 '/ 设置最小值 .Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0 .Plot.Axis(VtChAxisIdX).ValueScale.Minimum = 0 '/ .Plot.Axis(VtChAxisIdX).ValueScale.MajorDivision = 12 '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 = VtChChartType2dLine'!必须为线图,二维散点图只有一条线,用来表示散点分布情况 'MSChart1.chartType = VtChChartType2dXY '设置图形为二维散点图 MSChart1.ChartData = MyData '数据 End With 效果如下:成功加入了一条蓝色的。 多出来的红线是什么意思呢? 横坐标的R1,R2.这些怎更改呢? 拖一个mschart1到窗体上 代码如下,全部粘贴覆盖。 Option Explicit Private Sub Form_Load Dim MyData(12, 2) As Double '-x轴坐标值-Y轴坐标值- MyData(0, 2) = 100: MyData(0, 0) = 180 '本句代表了:第一点数据的X轴坐标为0,Y轴坐标为180 MyData(1, 2) = 11: MyData(1, 0) = 960 MyData(2, 2) = 112: MyData(2, 0) = 60 MyData(3, 2) = 103: MyData(3, 0) = 0 MyData(4, 2) = 44: MyData(4, 0) = 0 MyData(5, 2) = 55: MyData(5, 0) = 60 MyData(6, 2) = 66: MyData(6, 0) = 60 MyData(7, 2) = 77: MyData(7, 0) = 0 MyData(8, 2) = 28: MyData(8, 0) = 60 MyData(9, 2) = 9: MyData(9, 0) = 60 MyData(10, 2) = 110: MyData(10, 0) = 0 MyData(11, 2) = 101: MyData(11, 0) = 0 MyData(12, 2) = 112: MyData(12, 0) = 60 '波形图外观设置 With MSChart1 .TitleText = "值" ' '设置图线的外观 .Plot.SeriesCollection(1).Pen.Width = 30 .Plot.SeriesCollection(1).Pen.Style = VtPenStyleSolid .Plot.SeriesCollection(2).Pen.Width = 30 .Plot.SeriesCollection(2).Pen.Style = VtPenStyleNull'不显示第二条绿色线,只要红蓝 .Plot.SeriesCollection(3).Pen.Width = 30 .Plot.SeriesCollection(3).Pen.Style = VtPenStyleSolid ' '设置XY轴 .Plot.Axis(VtChAxisIdX).ValueScale.Auto = False .Plot.Axis(VtChAxisIdY).ValueScale.Auto = False '/ 设置最大值 .Plot.Axis(VtChAxisIdX).ValueScale.Maximum = 12 .Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 1000 '/ 设置最小值 .Plot.Axis(VtChAxisIdY).ValueScale.Minimum = 0 .Plot.Axis(VtChAxisIdX).ValueScale.Minimum = 0 '/ .Plot.Axis(VtChAxisIdX).ValueScale.MajorDivision = 12 '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 = VtChChartType2dLine '设置图形为线图 MSChart1.ChartData = MyData '数据 '设置R1-R13,其余以此类推。 Dim i As Integer For i = 1 To 13 .Row = i .RowLabel = i Next End With End Sub 红蓝两条线。