void AddDatum(TrendValue v, DateTime start, DateTime end, IList <ChartValue> timeData) { // for this math to work, we have to ignore "time" in the dates. start = start.Date; end = end.Date; // duplicate the items across a range to fill the gaps so the graph spans the whole time span. while (start < end) { string label = this.generator.GetLabel(v); timeData.Add(new ChartValue(label, (double)v.Value, v.UserData)); start = start.AddDays(1); } return; }
private TrendGraphSeries AddSeries(DateTime start, DateTime end, Color color) { ChartCategory cat = new ChartCategory(); cat.WpfColor = color; nfi.NumberDecimalDigits = 2; nfi.CurrencyNegativePattern = 0; TimeSpan span = (end - start); int days = span.Days; if (days > 360) { cat.Name = start.Year.ToString(); } else { cat.Name = start.ToShortDateString(); } TrendGraphSeries s = new TrendGraphSeries(cat.Name, cat.Name); chartData.AddSeries(s); s.Flipped = generator.IsFlipped; IList <ChartValue> timeData = s.Values; s.BeginUpdate(); DateTime last = start; TrendValue lastv = null; foreach (TrendValue v in this.data) { // calculate balances using data from the start of the account \ list so the end balance is correct if (v.Date <= end && v.Date >= start) { // If the items are on the same day, don't add to the graph yet. // Accumulate them and the accumulated value for the day will be displayed if (last != v.Date) { AddDatum(v, last, v.Date, timeData); } last = v.Date; lastv = v; } } // Put the last item on the graph if (lastv != null) { AddDatum(lastv, last, end.AddDays(1), timeData); } s.EndUpdate(); //s.Accumulate = false; //s.Color = color; s.Category = cat; s.Start = start; s.End = end; return(s); }
private TrendGraphSeries AddSeries(DateTime start, DateTime end, Color color) { ChartCategory cat = new ChartCategory(); cat.WpfColor = color; nfi.NumberDecimalDigits = 2; nfi.CurrencyNegativePattern = 0; TimeSpan span = (end - start); int days = span.Days; if (days > 360) { cat.Name = start.Year.ToString(); } else { cat.Name = start.ToShortDateString(); } TrendGraphSeries s = new TrendGraphSeries(cat.Name); chartData.AddSeries(s); s.Flipped = generator.IsFlipped; IList <ChartDataValue> timeData = s.Values; TrendValue emptyTrendValue = new TrendValue(); emptyTrendValue.Value = 0; emptyTrendValue.UserData = null; DateTime last = start; TrendValue lastv = emptyTrendValue; foreach (TrendValue v in this.data) { // NOTE: This list is assumed to be sorted if (v.Date > end) { break; } if (v.Date >= start) { // If the items are on the same day, don't add to the graph yet. // Accumulate them and the accumulated value for the day will be displayed if (last != v.Date) { AddDatum(lastv, last, v.Date, timeData); } last = v.Date; } lastv = v; } // Put the last item on the graph AddDatum(lastv, last, end.AddDays(1), timeData); //s.Accumulate = false; //s.Color = color; s.Category = cat; s.Start = start; s.End = end; return(s); }