I am trying to plot data represented by a bunch of dots connected with lines. However, when I do the plot, I can only see dots being displayed, but I cannot see any lines. I don't know what the problems are. Here is my code, and this is how LineAndMarker plotter is initiated:

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

and here is how the data of dynamic display is updated:

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

Basic idea is simple: create the plotter, then only update the data and color. I only see the red dots separated with each other, but I did not see any green, or whatever color lines are connecting those dots. I am confused. Anyone can point out where I did wrong? Thanks a lot.

有帮助吗?

解决方案

This is because I did not update line data. Here is the new code:

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

Here you can notice that not only marker data are updated, the line data also need to be updated. There is a DataSource for markers, and there is a DataSource for line. If you designate both sources, and you update both colors, you should be able to see lines and markers both.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top