VBA: Chart_Data points not visible in graph

喜你入骨 提交于 2021-02-11 18:24:39

问题


I dont get the line curve for the data given below however I see the data being plotted but not visible as a smooth line. Please help.

      Column B  Column C
          x      y

        0.00      0.00
       -0.10    0.29
       -0.35    0.48
       -0.65    0.48
       -0.90    0.29
       -1.00    0.00

         
      Set ch = ActiveSheet.ChartObjects("Chart 1")
      ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
     ch.Activate

     p=1
For i = 1 To 6
           
        ser_count = ActiveChart.SeriesCollection.Count
        p = ser_count + 1

         ActiveChart.SeriesCollection.NewSeries
        
       
        ActiveChart.SeriesCollection(p).XValues = ActiveSheet.Range("b" & i)
        ActiveChart.SeriesCollection(p).Values = ActiveSheet.Range("c" & i)

        ActiveChart.SeriesCollection(p).Format.Line.Visible = msoTrue
        ActiveChart.SeriesCollection(p).Format.Line.ForeColor.RGB = RGB(255, 0, 0)
        ActiveChart.SeriesCollection(p).Format.Line.Weight = 1
        ActiveChart.SeriesCollection(p).Format.Line.DashStyle = msoLineSolid

 Next i

回答1:


Try,

Dim objCh As ChartObject
Dim ch As Chart
Dim Srs As Series

Set objCh = ActiveSheet.ChartObjects("Chart 1")
'Set objCh = ActiveSheet.ChartObjects(1)
Set ch = objCh.Chart
With ch
    .ChartType = xlXYScatterSmoothNoMarkers
    
     Set Srs = .SeriesCollection.NewSeries
    With Srs
        .XValues = ActiveSheet.Range("b1").Resize(6)
        .Values = ActiveSheet.Range("c1").Resize(6)

        .Format.Line.Visible = msoTrue
        .Format.Line.ForeColor.RGB = RGB(255, 0, 0)
        .Format.Line.Weight = 1
        .Format.Line.DashStyle = msoLineSolid
    End With
End With


来源:https://stackoverflow.com/questions/64167500/vba-chart-data-points-not-visible-in-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!