2013-02-18 15 views
0

我正在嘗試繪製由線連接的點串表示的數據。但是,當我進行繪圖時,我只能看到正在顯示的點,但看不到任何線條。我不知道問題是什麼。這裏是我的代碼,這是LineAndMarker繪圖儀是如何開始:LineAndMarker <MarkerPointsGraph>僅查看標記,但沒有行?

public SignalStatsDisplay() 
     { 
      InitializeComponent(); 

      plotter.Legend.Remove(); 

      _initialChildrenCount = plotter.Children.Count; 

      int count = plotter.Children.Count; 

      //do not remove the initial children 
      if (count > _initialChildrenCount) 
      { 
       for (int i = count - 1; i >= _initialChildrenCount; i--) 
       { 
        plotter.Children.RemoveAt(i); 
       } 
      } 

      _nColorChannels = 4; 

      // _lineprofileColor = new Color[4]; 

      // _lineprofileColor[0] = Colors.Transparent; 
      //_lineprofileColor[1] = Colors.Red; 
      // _lineprofileColor[2] = Colors.Black; 
      // _lineprofileColor[3] = Colors.Blue; 

      LineAndMarker<MarkerPointsGraph> lam = new LineAndMarker<MarkerPointsGraph>(); 
      CirclePointMarker pm = new CirclePointMarker { Size = 5, Fill = Brushes.Red }; 

      if (_nColorChannels > 0) // plotter init 
      { 
       _dataX = new List<int[]>(); 
       _dataY = new List<int[]>(); 

       int[] dataXOneCh = new int[1]; 
       int[] dataYOneCh = new int[1]; 

       dataXOneCh[0] = 0; 
       dataYOneCh[0] = 0; 

       for (int i = 0; i < 4; i++) 
       { 
        _dataX.Add(dataXOneCh); // data x-y mapping init 
        _dataY.Add(dataYOneCh); 

        EnumerableDataSource<int> xOneCh = new EnumerableDataSource<int>(dataXOneCh); 
        EnumerableDataSource<int> yOneCh = new EnumerableDataSource<int>(dataYOneCh); 

        xOneCh.SetXMapping(xVal => xVal); 
        yOneCh.SetXMapping(yVal => yVal); 

        CompositeDataSource dsOneCh = new CompositeDataSource(xOneCh, yOneCh); 

        lam = plotter.AddLineGraph(dsOneCh, 
         (new Pen(Brushes.Green, 2)), 
         new CirclePointMarker { Size = 5, Fill = Brushes.Yellow }, 
         (new PenDescription("Data"))); 

       } 

       plotter.FitToView(); 
      } 
      else 
      { 
       return; 
      } 
     } 

,這裏是如何動態顯示的數據更新:

public void RedrawSignalAnalysisPlot() 
     { 
      int startIndex = _initialChildrenCount; 

      if ((_nColorChannels > 0) && (_dataX != null) && (_dataY != null)) 
      { 
       CompositeDataSource[] dsCh = new CompositeDataSource[_nColorChannels]; 

       //for (int i = 0; i < 4; i++) // color reset 
       // { 
       //  ((LineGraph)plotter.Children.ElementAt(startIndex + i)).LinePen = new Pen(new SolidColorBrush(Colors.Transparent), 1); 
       // } 

       for (int i = 0; i < 1; i++) 
       { 
        if (_dataX[i].Length == _dataY[i].Length) 
        { 
         EnumerableDataSource<int> xOneCh = new EnumerableDataSource<int>(_dataX[i]); 
         xOneCh.SetXMapping(xVal => xVal); 
         EnumerableDataSource<int> yOneCh = new EnumerableDataSource<int>(_dataY[i]); 
         yOneCh.SetYMapping(yVal => yVal); 
         CompositeDataSource ds = new CompositeDataSource(xOneCh, yOneCh); 

         Action UpdateData = delegate() 
         { 

          ((PointsGraphBase)plotter.Children.ElementAt(startIndex + i + 1)).DataSource = ds; 
          //((CirclePointMarker)plotter.Children.ElementAt(startIndex + i + 1)).Pen = new Pen(new SolidColorBrush(Colors.Green), 1);     

         }; 

         this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, UpdateData); 
        } 
       } 

       Action PlotFitToView = delegate() 
       { 
        plotter.FitToView(); 

       }; 
       this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, PlotFitToView); 
      } 
     } 

基本想法很簡單:創建繪圖,然後只更新數據和顏色。 我只看到彼此分開的紅點,但我沒有看到任何綠色,或任何顏色線連接這些點。我很困惑。任何人都可以指出我做錯了什麼地方?非常感謝。

回答

0

這是因爲我沒有更新行數據。下面是新的代碼:

Action UpdateData = delegate() 
         { 
          ((LineGraph)plotter.Children.ElementAt(startIndex + i)).DataSource = ds; 
          ((LineGraph)plotter.Children.ElementAt(startIndex + i)).LinePen = new Pen(new SolidColorBrush(Colors.Green), 1); 

          ((PointsGraphBase)plotter.Children.ElementAt(startIndex + i + 1)).DataSource = ds; 
          ((MarkerPointsGraph)plotter.Children.ElementAt(startIndex + i + 1)).Marker = new CirclePointMarker { Size = 5, Fill = Brushes.Red };     
         }; 

         this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, UpdateData); 

在這裏,你可以看到,不僅標記數據被更新,該行的數據也需要進行更新。有一個標記的DataSource,並且有一個DataSource用於行。如果您指定了兩個來源,並且您更新了兩種顏色,則應該可以同時看到線條和標記。

相關問題