2013-04-18 1 views
2

차트의 데이터 계열을 관리하는 클래스를 개발 중입니다. 그러나 새로운 계열을 추가 할 때 첫 번째 dataPoint에 0의 XValue가있는 경우 대신 XValue가 1 인 것으로 플롯에 표시됩니다. 추가 dataPoint를 추가하면 자체 수정됩니다. 아래 코드를 사용하여 생성자를 먼저 호출 한 다음 Initialize ("Series1", 0,0과 같은 데이터로)를 호출하면 나중에 AddPoint를 호출 할 수 있습니다. 누구가 무슨 일이 일어나는지 알아?VB.Net - 차트의 잘못된 x 값으로 플로팅하는 첫 번째 dataPoint

편집 : 내가 발견 한 바로는 시리즈에 데이터 포인트가 하나 뿐이고 데이터 포인트의 xValue가 0이 될 때 발생합니다. 시리즈는 하나 이상의 (또는 언젠가는) 데이터까지 올바르게 작동하지 않습니다 0이 아닌 xValues가있는 포인트가 추가됩니다. 내 해결 방법은 추가 할 데이터 요소의 xValue가 0 인 경우 xValue를 매우 작게 만듭니다 (1x10^-150). 일하는 것처럼 보이지만, 이것은 여전히 ​​내 책의 이상한 버그입니다. 나는 그것에 관한 어떤 정보도 찾을 수 없었다.

Public Sub New(ByVal chartObj As Chart) 
    'Init m_chart 
    m_chart = chartObj 

    m_chart.BackColor = Color.Gainsboro 

    'Init Legend 
    m_legend = New Legend("Legend") 
    m_legend.Docking = Docking.Bottom 
    m_chart.Legends.Add(m_legend) 

    'Init m_chartArea 

    m_chartArea = New ChartArea("Default") 

    m_chartArea.BackColor = Color.Black 

    m_chartArea.AxisX.LabelStyle.Format = "{0:0.00}" 

    setXLimits(-10, 10) 
    setYLimits(-0.5, 0.5) 

    m_chartArea.AxisX.Title = "Position (mm)" 
    m_chartArea.AxisX.TitleFont = New Font("Arial", 10, FontStyle.Regular) 

    m_chartArea.AxisY.Title = "Peak-To-Peak (Volts)" 
    m_chartArea.AxisY.TitleFont = New Font("Arial", 10, FontStyle.Regular) 

    m_chartArea.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash 
    m_chartArea.AxisX.MajorGrid.LineColor = Color.DarkGreen 
    m_chartArea.AxisY.MajorGrid.LineDashStyle = ChartDashStyle.Dash 
    m_chartArea.AxisY.MajorGrid.LineColor = Color.DarkGreen 

    m_chart.ChartAreas.Add(m_chartArea) 

    'Init m_dataSeries 
    m_dataSeries = New List(Of Series) 

    'Init m_markerSeries 
    m_markerSeries = New Series("Peaking Markers") 
    m_markerSeries.ChartType = SeriesChartType.Point 
    m_markerSeries.MarkerColor = Color.Red 
    m_markerSeries.MarkerStyle = MarkerStyle.Triangle 
    m_markerSeries.MarkerSize = 10 
    m_chart.Series.Add(m_markerSeries) 

    'Init m_title 
    m_title = New Title("Plots") 
    m_title.Font = New Font("Arial", 20, FontStyle.Regular) 
    m_chart.Titles.Add(m_title) 

End Sub 

Public Sub Initialize(ByVal Legend As String, ByVal xVal As Double, ByVal yVal As Double) 
    Dim temp As New Series(Legend) 
    temp.ChartType = SeriesChartType.Line 
    temp.Points.Clear() 

    If nextAxis = "X" Then 
     temp.Color = xColor 
     nextAxis = "Y" 
    Else 
     temp.Color = yColor 
     nextAxis = "X" 
    End If 

    temp.MarkerStyle = MarkerStyle.Circle 

    m_dataSeries.Add(temp) 
    m_chart.Series.Add(temp) 

    AddPoint(xVal, yVal) 

End Sub 

Public Sub AddPoint(ByVal x As Double, ByVal y As Double) 
    If m_chart.InvokeRequired Then 
     m_chart.Invoke(New Action(Of Double, Double)(AddressOf AddPoint), x, y) 
    Else 
     Dim temp As New DataPoint(x, y) 

     m_dataSeries.Item(m_dataSeries.Count - 1).Points.Add(temp) 
    End If 
End Sub 

답변

0

보십시오이 변경이로

If m_chart.InvokeRequired Then 
    m_chart.Invoke(New Action(Of Double, Double)(AddressOf AddPoint), x, y) 
Else 
    Dim temp As New DataPoint(x, y) 

    m_dataSeries.Item(m_dataSeries.Count - 1).Points.Add(temp) 
End If 

:

If m_chart.InvokeRequired Then 
    m_chart.Invoke(New Action(Of Double, Double)(AddressOf AddPoint), x, y) 
End If 

Dim temp As New DataPoint(x, y) 
m_dataSeries.Item(m_dataSeries.Count - 1).Points.Add(temp) 
0

년 8 월 2017 .NET 프레임 워크 4.5.2, 여전히 같은 버그 ...

I을 거품 형 차트를 만들고 단일 점을 추가하면

Chart1.Series("MySeries").AddXY(0,0,value) 

이상한 : 포인트 대신 (0,0) 의 위치 (1,0)에서 나타하지만 두 개 이상의 점을 추가하는 경우, 그것은 올바른 ...

그래서, 내 트릭은 비슷한 점이 있는데, 하나의 점만을 가지고있을 때, 두 점을 두 번 더하고, 작은 점은 실제 점에 의해 가려진다는 것을 알게됩니다. 그리 좋지는 않지만 속임수입니다.하지만 내 문제를 해결합니다.

Chart1.Series("MySeries").AddXY(0.000001,0,0) 
Chart1.Series("MySeries").AddXY(0,0,10) 

기타 제안 사항 : 환영합니다!

관련 문제