各位大虾,VB MSCHART画二维散点图,但出来的是二维曲线图。大家帮忙看看哪里有问题??谢谢
'画图
Public Sub ShowChart(Optional intAxisXMax As Integer, Optional intAxisXMin As Integer, Optional intAxisYMax As Integer, Optional intAxisYMin As Integer)
    '//判断是否需要修改X轴显示范围,用于动态显示
    With Me.MSChart1
        .ColumnCount = 16 '//当设置图形为二维散点图时.一条曲线需两个Column,例如两条曲线时,只需对Column=1和3操作,就可完成各自属性设置        
          '// 设置最大值
        .Plot.Axis(VtChAxisIdX).ValueScale.Maximum = intAxisXMax
         .Plot.Axis(VtChAxisIdY).ValueScale.Maximum = intAxisYMax
         '// 设置最小值
         .Plot.Axis(VtChAxisIdY).ValueScale.Minimum = intAxisYMin
         .Plot.Axis(VtChAxisIdX).ValueScale.Minimum = intAxisXMin
         '//设置图线的外观
         .Plot.SeriesCollection(1).Pen.Style = VtPenStyleSolid
         .Plot.Axis(VtChAxisIdX).ValueScale.MajorDivision = intAxisXMax 'X轴主要网格数量
         .Plot.Axis(VtChAxisIdY).ValueScale.MajorDivision = 29 'Y轴主要网格数量
         .Plot.Axis(VtChAxisIdX).ValueScale.MinorDivision = 0 'X轴次要网格数量
         .Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 0 'Y轴次要网格数量
         
         ' 255,0,0   红色
        ' 255,255,0 黄色
        ' 0,255,0   绿色
        ' 0,0,255   蓝色
        .Plot.SeriesCollection(1).Pen.VtColor.Set 0, 0, 255 '//第一条为实际曲线,设置为蓝色
        .Plot.SeriesCollection(1).Pen.Width = 40 '//设置为较细
        .Plot.SeriesCollection(3).Pen.VtColor.Set 0, 0, 0 '  0, 255, 0 '//第二条为目标曲线,设置为绿色
        .Plot.SeriesCollection(3).Pen.Width = 30    '//设置为较细
        .Plot.SeriesCollection(5).Pen.VtColor.Set 0, 0, 0 '  255, 255, 0 '//第三条为预警下限曲线,设置为黄色
        .Plot.SeriesCollection(5).Pen.Width = 30    '//设置为较细
        
        .Plot.SeriesCollection(7).Pen.VtColor.Set 0, 0, 0 '  255, 255, 0 '//第四条为预警上限曲线,设置为黄色
        .Plot.SeriesCollection(7).Pen.Width = 30    '//设置为较细
        .Plot.SeriesCollection(9).Pen.VtColor.Set 0, 0, 0 '  255, 0, 0 '//第五条为控制下限曲线,设置为红色
        .Plot.SeriesCollection(9).Pen.Width = 30    '//设置为较细
        .Plot.SeriesCollection(11).Pen.VtColor.Set 0, 0, 0 '  255, 0, 0 '//第六条为控制上限曲线,设置为红色
        .Plot.SeriesCollection(11).Pen.Width = 30    '//设置为较细
        .Plot.SeriesCollection(13).Pen.VtColor.Set 0, 0, 0 '  255, 0, 0 '//第7条为控制上限曲线,设置为红色
        .Plot.SeriesCollection(13).Pen.Width = 20    '//设置为较细
        .Plot.SeriesCollection(13).Pen.Style = VtPenStyleDashed
        .Plot.SeriesCollection(15).Pen.VtColor.Set 0, 0, 0 '  255, 0, 0 '//第8条为控制上限曲线,设置为红色
        .Plot.SeriesCollection(15).Pen.Width = 20    '//设置为较细
        .Plot.SeriesCollection(15).Pen.Style = VtPenStyleDashed
        '//设置X,Y轴不自动缩放,固定大小
        .Plot.Axis(VtChAxisIdX).ValueScale.Auto = False
        .Plot.Axis(VtChAxisIdY).ValueScale.Auto = False        .Plot.Axis(VtChAxisIdX).AxisGrid.MajorPen.Style = VtPenStyleSolid '//X轴网格为实线
        .Plot.Axis(VtChAxisIdY).AxisGrid.MajorPen.Style = VtPenStyleSolid '//Y轴网格为实线
        '//设置坐标系在MSChart控件框中的大小
        .Plot.AutoLayout = False '//改为手动设置大小
        .Plot.LocationRect.Min.X = 0
        .Plot.LocationRect.Min.Y = 0 '//设置最小坐标位置为0,即坐标系顶部和左边都靠着MSChart的边框
        .Plot.LocationRect.Max.X = .Width
        .Plot.LocationRect.Max.Y = .Height '//设置最大值为MSChart边框的长和宽,使坐标系右边和底部靠着边框
        .Plot.UniformAxis = False '//指定图表的所有值坐标轴的单位刻度不一致(X,Y轴坐标不需要一致).
        '//设置图形类型
        .ChartType = VtChChartType2dXY '//设置图形为二维散点图
        .ChartData = mydata '
         .Refresh
        
    End With
End Sub

解决方案 »

  1.   


    Sub Macro1()
    '
    ' Macro1 Macro
    ' ºêÓɠ΢ÈíÓû§ Â¼ÖÆ£¬Ê±¼ä: 2012-3-5
    ''
        Range("A1:B20").Select
        Charts.Add
        ActiveChart.ChartType = xlXYScatter
        ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:B20"), PlotBy _
            :=xlColumns
        ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
        With ActiveChart
            .HasTitle = False
            .Axes(xlCategory, xlPrimary).HasTitle = False
            .Axes(xlValue, xlPrimary).HasTitle = False
        End With
    End Sub
      

  2.   

    ActiveChart.ChartType = xlXYScatter
    这个在vb中mschart charttype没有这个值
      

  3.   

    的确
    我曾经试验过,VBA中和VB中不完全一样。
      

  4.   

    建议你使用PictureBox结合API函数来绘制散点图
      

  5.   

    我就不明白,为什么VB里mschart就不能画出2维散点,非得把2点间有曲线连起来。
      

  6.   

    MSChart1.Plot.SeriesCollection(index).ShowLine = False