/// <summary> /// Create chart series for each coin /// </summary> private void PlotPaymentChart() { try { // Exit if no fiat currency is selected if (Application.Current.Properties["Currency"] == null) { return; } // New list of strings used for labels when plotting the chart List <string> labels = new List <string>(); // New collection of series seriesCollection = new SeriesCollection(); foreach (MinerPaymentSummary MinerPaymentSummary in MinerPaymentsData.MinerPaymentSummaryList) { StackedAreaSeries stackedColumnSeries = new StackedAreaSeries(); ChartValues <DateTimePoint> chartValues = new ChartValues <DateTimePoint>(); // Format series fill, stroke, etc FormatChartSeries(MinerPaymentSummary, stackedColumnSeries); // Iterate through each day and add a chart point foreach (MinerPaymentsGroupedByDay minerPaymentsGroupedByDay in MinerPaymentSummary.MinerPaymentsGroupedByDayList.Where(x => x.PaymentDate >= DateTime.Now.AddDays(-30)).OrderByDescending(y => y.PaymentDate)) { DateTimePoint dateTimePoint = CreateChartDataPoint(minerPaymentsGroupedByDay); chartValues.Add(dateTimePoint); } // Add coin symbol to labels to show up in the UI labels.Add(MinerPaymentSummary.CoinType.ToString()); // Add 0 values for any dates with no payments in order to render the chart properly PaymentChartDataBackFill paymentChartDataBackFill = new PaymentChartDataBackFill(); stackedColumnSeries.Values = paymentChartDataBackFill.BackFillList(chartValues); seriesCollection.Add(stackedColumnSeries); } // Add a line series for the Total Line seriesCollection.Add(this.AddTotalLineSeries()); // Axis label formats XFormatter = val => new DateTime((long)val).ToShortDateString(); YFormatter = val => String.Format("{0} {1}", Math.Round(val, 4).ToString(), Application.Current.Properties["Currency"].ToString()); // Rebind UI OnPropertyChanged("SeriesCollection"); OnPropertyChanged("XFormatter"); OnPropertyChanged("YFormatter"); } catch (Exception e) { ShowError(String.Format("{0} {1}", "Error plotting payment chart", e.Message)); } }
/// <summary> /// Calculate the total payment amount for each day and create a total line series to plot /// </summary> /// <returns></returns> private LineSeries AddTotalLineSeries() { LineSeries totalLineSeries = new LineSeries(); ChartValues <DateTimePoint> chartValues = new ChartValues <DateTimePoint>(); // Group payments by date and get sum of all fiat payment amounts List <MinerPaymentsGroupedByDay> result = profitabilityData.MinerPaymentsGroupedByDayUnionedList .GroupBy(l => l.PaymentDateTicks) .Select(cl => new MinerPaymentsGroupedByDay { PaymentDateTicks = cl.First().PaymentDateTicks, PaymentAmountFiat = cl.Sum(c => c.PaymentAmountFiat) }).ToList(); // Iterate through each date and add new data points to the line series foreach (MinerPaymentsGroupedByDay minerPaymentsGroupedByDay in result) { DateTimePoint dateTimePoint = new DateTimePoint(); dateTimePoint.DateTime = minerPaymentsGroupedByDay.PaymentDate; dateTimePoint.Value = Convert.ToDouble(minerPaymentsGroupedByDay.PaymentAmountFiat); chartValues.Add(dateTimePoint); } PaymentChartDataBackFill paymentChartDataBackFill = new PaymentChartDataBackFill(); totalLineSeries.Values = paymentChartDataBackFill.BackFillList(chartValues); // Format series var converter = new System.Windows.Media.BrushConverter(); Brush brushStroke = (Brush)converter.ConvertFromString("#FFFFFF"); brushStroke.Opacity = 0; totalLineSeries.Title = "TOTAL"; totalLineSeries.LineSmoothness = 0.7; totalLineSeries.PointGeometrySize = 0; totalLineSeries.Stroke = brushStroke; totalLineSeries.StrokeThickness = 0; return(totalLineSeries); }