0

我正在尝试绘制由一堆与线相连的点表示的数据。但是,当我绘制绘图时,我只能看到显示的点,但看不到任何线条。我不知道有什么问题。这是我的代码,这就是 LineAndMarker 绘图仪的启动方式:

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);
            }
        }

基本思路很简单:创建绘图仪,然后只更新数据和颜色。我只看到彼此分开的红点,但我没有看到任何绿色,或者连接这些点的任何颜色线。我很困惑。谁能指出我哪里做错了?非常感谢。

4

1 回答 1

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);

在这里您可以注意到不仅标记数据被更新,线数据也需要更新。标记有一个数据源,线条有一个数据源。如果您指定两个来源,并更新两种颜色,您应该能够同时看到线条和标记。

于 2013-02-18T20:36:26.987 回答