Beispiel #1
0
        private void UpdateGraph(PlotModel model, MSet <EzDataPoint> points)
        {
            model.Series.Clear();
            var allSeries = new BMultiMap <string, EzDataPoint>((a, b) => string.CompareOrdinal(a, b));

            foreach (var dp in points)
            {
                allSeries.Add(dp.Series, dp);
            }

            // Add text labels to axis if the data uses text Parameters
            CategoryAxis cAxis = null;

            if (points.Any(dp => dp.Parameter is string))
            {
                var headings = new SortedSet <string>(points.Select(dp => dp.Parameter as string).WhereNotNull());
                cAxis = model.Axes.OfType <CategoryAxis>().SingleOrDefault();
                if (cAxis == null)
                {
                    model.Axes.Add(cAxis = new CategoryAxis {
                        MajorGridlineStyle = LineStyle.Dot,
                        Position           = AxisPosition.Bottom
                    });
                }
                cAxis.Labels.Clear();
                foreach (var text in headings)
                {
                    cAxis.Labels.Add(text);
                }
                cAxis.Key = "CategoryAxis";
            }

            int iSeries = 0;

            foreach (var series in allSeries.Values)
            {
                if (series.Any(p => p.Parameter is string))
                {
                    var plotSeries = new ColumnSeries {
                        Title = series.First().Series
                    };
                    plotSeries.XAxisKey = cAxis.Key;
                    foreach (var dp in series)
                    {
                        plotSeries.Items.Add(new ColumnItem(dp.Value, cAxis.Labels.IndexOf(dp.Parameter.ToString())));
                    }
                    model.Series.Add(plotSeries);
                }
                else
                {
                    var plotSeries = new LineSeries {
                        Title = series.First().Series
                    };
                    if (cAxis != null)
                    {
                        plotSeries.XAxisKey = cAxis.Key;
                    }
                    // There are 7 marker types starting at 1, excluding None (0)
                    plotSeries.MarkerType = (MarkerType)((iSeries % 7) + 1);
                    plotSeries.MarkerSize = 4;
                    plotSeries.MarkerFill = plotSeries.Color;
                    foreach (var dp in series)
                    {
                        plotSeries.Points.Add(new OxyPlot.DataPoint(Convert.ToDouble(dp.Parameter), dp.Value));
                    }
                    model.Series.Add(plotSeries);
                }
                iSeries++;
            }
        }