Esempio n. 1
0
            public void AreaSeries()
            {
                var s1 = new OxyPlot.Series.AreaSeries();
                var s2 = new AreaSeries();

                OxyAssert.PropertiesAreEqual(s1, s2);
            }
Esempio n. 2
0
        /// <summary>
        /// Adds an area series to the plot
        /// </summary>
        /// <param name="title">The title of the series</param>
        /// <param name="description">The description of the series</param>
        /// <param name="isVisible">Initial visibility given to the series</param>
        /// <returns>The id given to the new line series. -1 if it fails</returns>
        public int AddAreaSeries(string title, string description = "", bool isVisible = true)
        {
            //TODO: improve how to limit the number of plots
            //For now, we just ignore series after the max number has been reached
            if (m_areaSeries.Count < m_maxNumSeries)
            {
                if (m_lock == null) //might be null if loaded from file
                {
                    m_lock = new object();
                }
                lock (m_lock)
                {
                    OxyPlot.Series.AreaSeries newSeries = new OxyPlot.Series.AreaSeries();
                    newSeries.Fill            = OxyPlot.OxyColor.FromAColor(120, Plot.DefaultColors[m_areaSeries.Count]);
                    newSeries.StrokeThickness = 1;
                    newSeries.Color           = OxyPlot.OxyColor.FromAColor(120, Plot.DefaultColors[m_areaSeries.Count]);
                    newSeries.Color2          = OxyPlot.OxyColor.FromAColor(120, Plot.DefaultColors[m_areaSeries.Count]);
                    newSeries.IsVisible       = isVisible;
                    Plot.Series.Add(newSeries);
                    m_areaSeries.Add(newSeries);

                    return(m_areaSeries.Count - 1);;
                }
            }
            return(-1);
        }
Esempio n. 3
0
        public void AddValue(string name, double value, DateTime?xValue = null, bool savePlot = true, bool replace = false)
        {
            if (xValue == null)
            {
                xValue = DateTime.UtcNow;
            }
            if (StartTime == null)
            {
                StartTime = xValue;
            }
            var relativeXValue = RelativeTime.Value ? new DateTime(1970, 01, 01).Add((xValue - StartTime).Value) : xValue;

            if (areaSeries.LastOrDefault()?.Title?.Equals(name) ?? false)
            {
                if (replace)
                {
                    areaSeries.Last().Points.RemoveAt(areaSeries.Last().Points.Count - 1);
                }

                areaSeries.Last().Points.Add(new DataPoint(DateTimeAxis.ToDouble(relativeXValue), value));
            }

            else
            {
                var series = new OxyPlot.Series.AreaSeries();
                //series.InterpolationAlgorithm = InterpolationAlgorithms.CatmullRomSpline;

                var colour = StringToColour(name);
                series.Color  = colour;
                series.Fill   = OxyColor.FromAColor(100, colour);
                series.Color2 = OxyColors.Transparent;

                if (!areaSeries.Any(x => x.Title?.Equals(name) ?? false))
                {
                    series.Title = name;
                }

                series.StrokeThickness = 3;
                areaSeries.LastOrDefault()?.Points?.Add(new DataPoint(DateTimeAxis.ToDouble(relativeXValue), value));
                series.Points.Add(new DataPoint(DateTimeAxis.ToDouble(relativeXValue), value));
                viewerChart.Series.Add(series);
                areaSeries.Add(series);
            }

            if (savePlot)
            {
                if (replace)
                {
                    PlotDataPoints.RemoveAt(PlotDataPoints.Count - 1);
                }

                PlotDataPoints.Add(new KeyValuePair <string, KeyValuePair <double, double> >(name, new KeyValuePair <double, double>(DateTimeAxis.ToDouble(xValue), value)));
                AdjustAxisRange();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a value to a given area series
        /// </summary>
        /// <param name="seriesIndex">Index of the series</param>
        /// <param name="xValue">The x value</param>
        /// <param name="maxYValue">The upper y value</param>
        /// <param name="minYValue">The lower y value</param>
        public void AddAreaSeriesValue(int seriesIndex, double xValue, double maxYValue, double minYValue)
        {
            if (seriesIndex < 0 || seriesIndex >= m_areaSeries.Count)
            {
                //TODO: at least, we should log the error
                return;
            }

            OxyPlot.Series.AreaSeries series = m_areaSeries[seriesIndex];
            UpdatePlotBounds(xValue, maxYValue); //Not very efficient, but doesn't seem to be worth the effort right now
            UpdatePlotBounds(xValue, minYValue);
            series.Points.Add(new DataPoint(xValue, maxYValue));
            series.Points2.Add(new DataPoint(xValue, minYValue));
        }
        private Series ConvertSeries(ChartSeriesViewModel series)
        {
            Series newSeries   = null;
            var    valueSeries = series.GetScaleForProperty(series.ValueMemberPath);
            var    labelSeries = series.GetScaleForProperty(series.LabelMemberPath);


            switch (series.SeriesType)
            {
            case (ChartSeriesType.Column):
            {
                newSeries = new ColumnSeries
                {
                    ValueField  = series.ValueMemberPath,
                    ItemsSource = series.DataSource.Data,
                    FillColor   = valueSeries.Color.ToOxyColor(),
                    StrokeColor = valueSeries.Color.ToOxyColor(),
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };

                break;
            }

            case (ChartSeriesType.Line):
            {
                newSeries = new LineSeries
                {
                    ItemsSource = series.DataSource.Data,
                    DataFieldX  = series.XMemberPath,
                    DataFieldY  = series.YMemberPath,
                    MarkerType  = MarkerType.Circle,
                    Color       = valueSeries.Color.ToOxyColor(),
                    MarkerFill  = valueSeries.Color.ToOxyColor(),
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };
                break;
            }

            case (ChartSeriesType.Spline):
            {
                newSeries = new LineSeries
                {
                    ItemsSource = series.DataSource.Data,
                    DataFieldX  = series.XMemberPath,
                    DataFieldY  = series.YMemberPath,
                    MarkerType  = MarkerType.Circle,
                    Color       = valueSeries.Color.ToOxyColor(),
                    MarkerFill  = valueSeries.Color.ToOxyColor(),
                    Smooth      = true,
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };
                break;
            }

            case (ChartSeriesType.Area):
            {
                newSeries = new AreaSeries
                {
                    ItemsSource = series.DataSource.Data,
                    DataFieldX  = series.XMemberPath,
                    DataFieldY  = series.YMemberPath,
                    Color       = valueSeries.Color.ToOxyColor(),
                    Fill        = valueSeries.Color.ToOxyColor(),
                    MarkerFill  = valueSeries.Color.ToOxyColor(),
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };
                break;
            }

            case (ChartSeriesType.SplineArea):
            {
                newSeries = new AreaSeries
                {
                    ItemsSource = series.DataSource.Data,
                    DataFieldX  = series.XMemberPath,
                    DataFieldY  = series.YMemberPath,
                    Color       = valueSeries.Color.ToOxyColor(),
                    Fill        = valueSeries.Color.ToOxyColor(),
                    MarkerFill  = valueSeries.Color.ToOxyColor(),
                    Smooth      = true,
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };
                break;
            }

            case (ChartSeriesType.Bubble):
            {
                newSeries = new ScatterSeries
                {
                    ItemsSource   = series.DataSource.Data,
                    DataFieldX    = series.XMemberPath,
                    DataFieldY    = series.YMemberPath,
                    DataFieldSize = series.RadiusMemberPath,
                    MarkerFill    = valueSeries.Color.ToOxyColor(),
                    MarkerType    = MarkerType.Circle,
                    YAxisKey      = valueSeries.Name,
                    XAxisKey      = labelSeries.Name,
                };
                break;
            }

            case (ChartSeriesType.StepLine):
            {
                newSeries = new StairStepSeries
                {
                    ItemsSource = series.DataSource.Data,
                    DataFieldX  = series.XMemberPath,
                    DataFieldY  = series.YMemberPath,
                    Color       = valueSeries.Color.ToOxyColor(),
                    YAxisKey    = valueSeries.Name,
                    XAxisKey    = labelSeries.Name,
                };
                break;
            }

            default:
            {
                return(null);
            }
            }

            newSeries.Title = series.Name;

            return(newSeries);
        }
Esempio n. 6
0
 public void AreaSeries()
 {
     var s1 = new OxyPlot.Series.AreaSeries();
     var s2 = new AreaSeries();
     OxyAssert.PropertiesAreEqual(s1, s2);
 }
        void _presenter_CumaltiveFlowDataUpdate(object sender, Presenters.CumlativeFlow.CumaltiveFlowDataUpdateEventArgs e)
        {
            Dispatcher.Invoke(new Action(() =>
            {
                var data = this.DataContext as GraphModel;
                if (data != null)
                {
                    int readyCount     = e.Lanes.Count(l => l.Type == CumlativeFlowLaneType.Ready);
                    int inProcessCount = e.Lanes.Count(l => l.Type == CumlativeFlowLaneType.InProcess);
                    int completedCount = e.Lanes.Count(l => l.Type == CumlativeFlowLaneType.Completed);

                    int readyIndex     = 0;
                    int inProcessIndex = 0;
                    int completedIndex = 0;

                    var series = data.Model.Series;
                    series.Clear();
                    int[] y = new int[_presenter.NumberOfDaysHistory];
                    for (int i = e.Lanes.Count - 1; i >= 0; i--)
                    {
                        var lane       = e.Lanes[i];
                        var seriesData = new OxyPlot.Series.AreaSeries {
                            Title = lane.Title
                        };
                        seriesData.LineStyle = OxyPlot.LineStyle.None;
                        seriesData.Points.Add(new OxyPlot.DataPoint((-_presenter.NumberOfDaysHistory) + 1, 0));
                        for (int x = 0; x < lane.PointsPerDay.Count; x++)
                        {
                            y[x] += lane.PointsPerDay[x];
                            seriesData.Points.Add(new OxyPlot.DataPoint((-_presenter.NumberOfDaysHistory) + x + 1, y[x]));
                        }
                        seriesData.Points.Add(new OxyPlot.DataPoint(0, 0));

                        OxyColor colour = Graph.Model.DefaultColors[i % Graph.Model.DefaultColors.Count];
                        switch (lane.Type)
                        {
                        case CumlativeFlowLaneType.Ready:
                            colour = InterpolateColour(e.ReadyStartColour, e.ReadyEndColour, readyIndex, readyCount);
                            readyIndex++;
                            break;

                        case CumlativeFlowLaneType.InProcess:
                            colour = InterpolateColour(e.InProcessStartColour, e.InProcessEndColour, inProcessIndex, inProcessCount);
                            inProcessIndex++;
                            break;

                        case CumlativeFlowLaneType.Completed:
                            colour = InterpolateColour(e.CompleteStartColour, e.CompleteEndColour, completedIndex, completedCount);
                            completedIndex++;
                            break;

                        default:
                            // Just use the currently set value
                            break;
                        }

                        seriesData.Fill  = colour;
                        seriesData.Color = OxyColors.Transparent;

                        series.Insert(0, seriesData);
                    }
                }

                Graph.Model.InvalidatePlot(true);
            }));
        }
        private Series ConvertSeries(ChartSeriesViewModel series)
        {
            Series newSeries = null;
            var valueSeries = series.GetScaleForProperty(series.ValueMemberPath);
            var labelSeries = series.GetScaleForProperty(series.LabelMemberPath);

            switch (series.SeriesType)
            {
                case( ChartSeriesType.Column):
                {
                    newSeries = new ColumnSeries
                    {
                        ValueField = series.ValueMemberPath,
                        ItemsSource = series.DataSource.Data,
                        FillColor = valueSeries.Color.ToOxyColor(),
                        StrokeColor = valueSeries.Color.ToOxyColor(),
                        YAxisKey = valueSeries.Name,
                        XAxisKey = labelSeries.Name,
                    };

                    break;
                }
                case( ChartSeriesType.Line ):
                {
                    newSeries = new LineSeries
                    {
                        ItemsSource = series.DataSource.Data,
                        DataFieldX = series.XMemberPath,
                        DataFieldY = series.YMemberPath,
                        MarkerType = MarkerType.Circle,
                        Color = valueSeries.Color.ToOxyColor(),
                        MarkerFill = valueSeries.Color.ToOxyColor(),
                        YAxisKey = valueSeries.Name,
                        XAxisKey = labelSeries.Name,
                    };
                    break;
                }
                case( ChartSeriesType.Spline):
                {
                    newSeries = new LineSeries
                    {
                        ItemsSource = series.DataSource.Data,
                        DataFieldX = series.XMemberPath,
                        DataFieldY = series.YMemberPath,
                        MarkerType = MarkerType.Circle,
                        Color = valueSeries.Color.ToOxyColor(),
                        MarkerFill = valueSeries.Color.ToOxyColor(),
                        Smooth = true,
                        YAxisKey = valueSeries.Name,
                        XAxisKey = labelSeries.Name,
                    };
                    break;
                }
                case(ChartSeriesType.Area):
                {
                    newSeries = new AreaSeries
                    {
                        ItemsSource = series.DataSource.Data,
                        DataFieldX = series.XMemberPath,
                        DataFieldY = series.YMemberPath,
                        Color = valueSeries.Color.ToOxyColor(),
                        Fill = valueSeries.Color.ToOxyColor(),
                        MarkerFill = valueSeries.Color.ToOxyColor(),
                        YAxisKey = valueSeries.Name,
                        XAxisKey = labelSeries.Name,
                    };
                    break;
                }
                case( ChartSeriesType.SplineArea):
                {
                    newSeries = new AreaSeries
                    {
                        ItemsSource = series.DataSource.Data,
                        DataFieldX = series.XMemberPath,
                        DataFieldY = series.YMemberPath,
                        Color = valueSeries.Color.ToOxyColor(),
                        Fill = valueSeries.Color.ToOxyColor(),
                        MarkerFill = valueSeries.Color.ToOxyColor(),
                        Smooth = true,
                        YAxisKey = valueSeries.Name,
                        XAxisKey = labelSeries.Name,
                    };
                    break;
                }
                case(ChartSeriesType.Bubble):
                {
                    newSeries = new ScatterSeries
                    {
                        ItemsSource = series.DataSource.Data,
                        DataFieldX = series.XMemberPath,
                        DataFieldY = series.YMemberPath,
                        DataFieldSize = series.RadiusMemberPath,
                        MarkerFill = valueSeries.Color.ToOxyColor(),
                        MarkerType = MarkerType.Circle,
                        YAxisKey = valueSeries.Name,
                        XAxisKey = labelSeries.Name,
                    };
                    break;
                }
                case( ChartSeriesType.StepLine):
                {
                    newSeries = new StairStepSeries
                    {
                        ItemsSource = series.DataSource.Data,
                        DataFieldX = series.XMemberPath,
                        DataFieldY = series.YMemberPath,
                        Color = valueSeries.Color.ToOxyColor(),
                        YAxisKey = valueSeries.Name,
                        XAxisKey = labelSeries.Name,
                    };
                    break;
                }
                default:
                {
                    return null;
                }
            }

            newSeries.Title = series.Name;

            return newSeries;
        }
Esempio n. 9
0
        public static PlotModel LoadChartData(WhlSKU paraSku)
        {
            if (paraSku != null)
            {
                var plotArea   = new PlotModel();
                var endDate    = DateTime.Now.ToOADate();
                var startDate  = DateTime.Now.AddMonths(-6).ToOADate();
                var bottomAxis =
                    new OxyPlot.Axes.DateTimeAxis
                {
                    Position          = AxisPosition.Bottom,
                    Maximum           = Convert.ToDouble(endDate),
                    AbsoluteMaximum   = Convert.ToDouble(endDate),
                    Title             = "Date",
                    StringFormat      = "dd/M",
                    MinorIntervalType = DateTimeIntervalType.Days
                };


                var leftAxis = new OxyPlot.Axes.LinearAxis
                {
                    Position        = AxisPosition.Left,
                    Minimum         = 0,
                    AbsoluteMinimum = 0,
                    Title           = "Sales"
                };
                var rightAxis = new OxyPlot.Axes.LinearAxis
                {
                    Position        = AxisPosition.Right,
                    Minimum         = 0,
                    AbsoluteMinimum = 0,
                    Maximum         = 5000,
                    Title           = "Stock"
                };


                var query     = @"SELECT a.shortSku, a.stockDate, a.Stocklevel, a.StockMinimum, b.maintotal 
                          FROM whldata.stock_history as a
                            LEFT JOIN(SELECT top (999999999999) a.orderdate, a.shortsku, sum(a.total)as ""maintotal"" FROM
                            (SELECT top (999999999999) orderdate, sku, SUBSTRING(sku, 0, 8) as ""shortsku"", sum(salequantity) as ""sales"", CAST(SUBSTRING(sku, 8, 4) as /*unsigned*/ int) as ""packsize"", sum(salequantity * CAST(SUBSTRING(sku, 8, 4) as /*unsigned*/ int)) as 'total'
                             FROM whldata.newsales_raw
                             WHERE sku LIKE '" + paraSku.ShortSku + @"%'
                             group by sku, orderDate
                             order by orderdate) as a
                            GROUP BY orderdate, shortsku
                            ORDER BY orderDate) as b
                            on b.shortsku = SUBSTRING(a.shortSku, 0, 8) AND b.orderDate = a.stockDate
                            WHERE a.shortsku = '" + paraSku.SKU + @"'
                            ORDER BY StockDate ASC";
                var queryDict = SQLServer.MSSelectDataDictionary(query);
                if (queryDict == null)
                {
                    throw new NullReferenceException();
                }

                var stockHistoryPoints     = new List <DataPoint>();
                var salesHistoryPoints     = new List <DataPoint>();
                var stockHistoryFillPoints = new List <DataPoint>();
                var salesHistoryFillPoints = new List <DataPoint>();


                var salesSeries = new LineSeries();
                var stockSeries = new LineSeries();

                OxyPlot.Series.AreaSeries stockAreaSeries = new OxyPlot.Series.AreaSeries();
                OxyPlot.Series.AreaSeries salesAreaSeries = new OxyPlot.Series.AreaSeries();
                var maxStock = 0;
                var maxSales = 0;
                if (queryDict.Count != 0)
                {
                    try
                    {
                        bottomAxis.AbsoluteMinimum =
                            Convert.ToDouble(DateTime.Parse((queryDict[0])["stockDate"].ToString()).ToOADate());
                        bottomAxis.Minimum =
                            Convert.ToDouble(DateTime.Parse((queryDict[0])["stockDate"].ToString()).ToOADate());
                    }
                    catch (Exception)
                    {
                        bottomAxis.AbsoluteMinimum = Convert.ToDouble(startDate);
                        bottomAxis.Minimum         = Convert.ToDouble(startDate);
                    }

                    foreach (var result in queryDict)
                    {
                        var    stockTotal = Convert.ToDouble(int.Parse(result["Stocklevel"].ToString()));
                        double salesTotal;

                        try
                        {
                            if (maxStock < int.Parse(result["Stocklevel"].ToString()) + int.Parse(result["StockMinimum"].ToString()))
                            {
                                maxStock = int.Parse(result["Stocklevel"].ToString()) + int.Parse(result["StockMinimum"].ToString());
                            }
                            if (DBNull.Value != result["maintotal"])
                            {
                                if (maxSales < int.Parse(result["maintotal"].ToString()))
                                {
                                    maxSales = int.Parse(result["maintotal"].ToString());
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                        salesTotal = Convert.ToDouble(result["maintotal"] == DBNull.Value ? 0 : int.Parse(result["maintotal"].ToString()));


                        var date = Convert.ToDouble(DateTime.Parse(result["stockDate"].ToString()).ToOADate());
                        var stockHistoryPoint  = new DataPoint(date, stockTotal);
                        var saleHistoryPoint   = new DataPoint(date, salesTotal);
                        var stockHistoryPoint2 = new DataPoint(date, 0);
                        salesHistoryPoints.Add(saleHistoryPoint);
                        stockHistoryPoints.Add(stockHistoryPoint);

                        salesHistoryFillPoints.Add(stockHistoryPoint2);
                        stockHistoryFillPoints.Add(stockHistoryPoint2);
                    }
                }
                else
                {
                    var queryDict2 = SQLServer.MSSelectData(
                        "SELECT StockLevel,StockMinimum,StockDate from whldata.stock_history WHERE sku="
                        + paraSku.ShortSku + "';") as ArrayList;
                    if (queryDict2 != null)
                    {
                        foreach (ArrayList result in queryDict2)
                        {
                            if (maxStock < int.Parse(result[0].ToString()) + int.Parse(result[1].ToString()))
                            {
                                maxStock = int.Parse(result[0].ToString()) + int.Parse(result[1].ToString());
                            }

                            var stockLevel         = Convert.ToDouble(int.Parse(result[0].ToString()));
                            var date               = Convert.ToDouble(DateTime.Parse(result[2].ToString()).ToOADate());
                            var stockHistoryPoint  = new DataPoint(date, stockLevel);
                            var stockHistoryPoint2 = new DataPoint(date, 0);
                            stockHistoryPoints.Add(stockHistoryPoint);
                            stockHistoryFillPoints.Add(stockHistoryPoint2);
                        }
                    }
                }

                salesSeries.Points.AddRange(salesHistoryPoints);
                stockSeries.Points.AddRange(stockHistoryPoints);


                rightAxis.Key        = "StockKey";
                salesSeries.YAxisKey = leftAxis.Key;
                salesSeries.CanTrackerInterpolatePoints = false;
                salesSeries.Color    = OxyColor.FromRgb(237, 125, 49);
                salesSeries.Title    = "Sales History";
                stockSeries.YAxisKey = rightAxis.Key;
                stockSeries.CanTrackerInterpolatePoints = false;

                stockAreaSeries.Points.AddRange(stockHistoryPoints);
                stockAreaSeries.YAxisKey = rightAxis.Key;
                stockAreaSeries.CanTrackerInterpolatePoints = false;
                stockAreaSeries.Fill   = OxyColor.FromRgb(176, 195, 230);
                stockAreaSeries.Color  = OxyColor.FromRgb(138, 167, 218);
                stockAreaSeries.Color2 = OxyColor.FromRgb(138, 167, 218);
                stockAreaSeries.Points2.AddRange(stockHistoryFillPoints);

                stockAreaSeries.Title = "Stock History Area";

                salesAreaSeries.Points.AddRange(salesHistoryPoints);
                salesAreaSeries.CanTrackerInterpolatePoints = false;
                salesAreaSeries.Fill   = OxyColor.FromArgb(140, 237, 125, 49);
                salesAreaSeries.Color  = OxyColor.FromArgb(255, 138, 167, 218);
                salesAreaSeries.Color2 = OxyColor.FromRgb(138, 167, 218);
                salesAreaSeries.Points2.AddRange(stockHistoryFillPoints);

                salesAreaSeries.Title = "Sales History Area";


                plotArea.Series.Add(stockAreaSeries);
                plotArea.Series.Add(salesAreaSeries);


                if (maxSales == 0)
                {
                    leftAxis.AbsoluteMaximum   = 1;
                    rightAxis.AbsoluteMaximum += 10;
                    leftAxis.Title             = "No sales";
                }
                if (maxSales > 0)
                {
                    leftAxis.AbsoluteMaximum  = (maxSales * 1.15) + 10;
                    leftAxis.Maximum          = (maxSales * 1.1) + 10;
                    rightAxis.Maximum         = maxStock * 1.1;
                    rightAxis.AbsoluteMaximum = maxStock * 1.15;
                }

                rightAxis.AbsoluteMaximum = maxStock;
                plotArea.Axes.Add(bottomAxis);
                plotArea.Axes.Add(leftAxis);
                plotArea.Axes.Add(rightAxis);

                plotArea.Title = paraSku.ShortSku + " Sales/Stock History";

                return(plotArea);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref = "AreaSeries" /> class.
 /// </summary>
 public AreaSeries()
 {
     InternalSeries = new OxyPlot.Series.AreaSeries();
 }
Esempio n. 11
0
        private void CreateRelativeCapitalUsageByStrategyChartModel()
        {
            var model = new PlotModel();

            var xAxis = new OxyPlot.Axes.DateTimeAxis
            {
                Position     = OxyPlot.Axes.AxisPosition.Bottom,
                StringFormat = "yyyy-MM-dd"
            };

            model.Axes.Add(xAxis);

            var yAxis = new OxyPlot.Axes.LinearAxis
            {
                Position           = OxyPlot.Axes.AxisPosition.Left,
                StringFormat       = "p0",
                MajorGridlineStyle = LineStyle.Dash
            };

            model.Axes.Add(yAxis);

            var capUsageTmpSum = Enumerable.Range(0, Data.RelativeCapitalUsageByStrategy.Rows.Count).Select(x => 0.0).ToList();

            foreach (DataColumn column in Data.RelativeCapitalUsageByStrategy.Columns)
            {
                if (column.ColumnName == "date")
                {
                    continue;
                }

                DataColumn    column1 = column;
                List <double> sum     = capUsageTmpSum;
                var           series  = new OxyPlot.Series.AreaSeries
                {
                    ItemsSource = Data
                                  .RelativeCapitalUsageByStrategy
                                  .Select((x, i) =>
                                          new
                    {
                        X  = x.date,
                        Y  = sum[i],
                        Y2 = sum[i] + x.Field <double>(column1.ColumnName),
                    }),

                    Title = column.ColumnName,
                    CanTrackerInterpolatePoints = false,
                    TrackerFormatString         = "Strategy: " + column.ColumnName + @" Date: {2:yyyy-MM-dd} Capital Usage: {4:p1}",
                    DataFieldX      = "X",
                    DataFieldX2     = "X",
                    DataFieldY      = "Y",
                    DataFieldY2     = "Y2",
                    MarkerType      = MarkerType.None,
                    StrokeThickness = 1
                };

                capUsageTmpSum = Data.RelativeCapitalUsageByStrategy.Select((x, i) => x.Field <double>(column1.ColumnName) + capUsageTmpSum[i]).ToList();

                model.Series.Add(series);
            }

            model.LegendPosition    = LegendPosition.BottomCenter;
            model.LegendOrientation = LegendOrientation.Horizontal;
            model.LegendPlacement   = LegendPlacement.Outside;

            RelativeCapitalUsageByStrategyModel = model;
        }
Esempio n. 12
0
        void CalculateSeriesBounds(out double minX, out double maxX, out double minY, out double maxY)
        {
            minY = double.MaxValue;
            maxY = double.MinValue;
            minX = double.MaxValue;
            maxX = double.MinValue;
            bool atLeastOneLineSeries = false;

            foreach (OxyPlot.Series.Series series in Plot.Series)
            {
                if (series is OxyPlot.Series.LineSeries)
                {
                    OxyPlot.Series.LineSeries lineSeries = series as OxyPlot.Series.LineSeries;
                    if (lineSeries.IsVisible && lineSeries.Points.Count > 0)
                    {
                        atLeastOneLineSeries = true;
                        foreach (DataPoint dataPoint in lineSeries.Points)
                        {
                            if (dataPoint.Y < minY)
                            {
                                minY = dataPoint.Y;
                            }
                            if (dataPoint.Y > maxY)
                            {
                                maxY = dataPoint.Y;
                            }
                            if (dataPoint.X < minX)
                            {
                                minX = dataPoint.X;
                            }
                            if (dataPoint.X > maxX)
                            {
                                maxX = dataPoint.X;
                            }
                        }
                    }
                }

                if (series is OxyPlot.Series.AreaSeries)
                {
                    OxyPlot.Series.AreaSeries areaSeries = series as OxyPlot.Series.AreaSeries;
                    if (areaSeries.IsVisible && areaSeries.Points.Count > 0)
                    {
                        foreach (DataPoint dataPoint in areaSeries.Points)
                        {
                            if (dataPoint.Y < minY)
                            {
                                minY = dataPoint.Y;
                            }
                            if (dataPoint.Y > maxY)
                            {
                                maxY = dataPoint.Y;
                            }
                            if (dataPoint.X < minX)
                            {
                                minX = dataPoint.X;
                            }
                            if (dataPoint.X > maxX)
                            {
                                maxX = dataPoint.X;
                            }
                        }
                        foreach (DataPoint dataPoint in areaSeries.Points2)
                        {
                            if (dataPoint.Y < minY)
                            {
                                minY = dataPoint.Y;
                            }
                            if (dataPoint.Y > maxY)
                            {
                                maxY = dataPoint.Y;
                            }
                            if (dataPoint.X < minX)
                            {
                                minX = dataPoint.X;
                            }
                            if (dataPoint.X > maxX)
                            {
                                maxX = dataPoint.X;
                            }
                        }
                    }
                }
            }
            if (!atLeastOneLineSeries)
            {
                minX = 0.0;
                maxX = 1.0;
                minY = 0.0;
                maxY = 1.0;
            }
        }