public void Stacked_Chart(bool change) { DateTime from_month = new DateTime(); DateTime to_month = new DateTime(); string selected_person = ""; Dispatcher.Invoke(() => { from_month = new DateTime(Convert.ToDateTime(date_month_from.SelectedDate).Year, Convert.ToDateTime(date_month_from.SelectedDate).Month, 1); to_month = Convert.ToDateTime(date_month_to.SelectedDate); selected_person = HoldersItems.Where(r => r.IsChecked == true).Select(x => x.HolderName).First(); StackedSeriesCollection.Clear(); }); DataTable dt = BrokerageAsset.GetHistoricalInvestments(selected_person, null, null, from_month, to_month); IEnumerable <string> selectcategories = InvestmentCategory.Getcategories(); Brush[] colors = { Brushes.DarkGreen, Brushes.ForestGreen, Brushes.Gainsboro, Brushes.DimGray, Brushes.Gold, Brushes.Orange, Brushes.DarkBlue }; Dispatcher.Invoke(() => { int count = 0; foreach (string category in selectcategories) { ChartValues <DateModel> chartvalues = new ChartValues <DateModel>(dt.AsEnumerable().Where(r => r["category"].ToString() == category) .Select(r => new DateModel { DateTime = r.Field <DateTime>("date"), Value = r.Field <double?>("ending_mkt_value") ?? 0 })); if (chartvalues.Count != 0) { StackedSeriesCollection.Add(new StackedColumnSeries { Values = chartvalues, StackMode = StackMode.Values, Title = category, Fill = colors[count], DataLabels = true, LabelPoint = point => (point.Y / 1000).ToString("C1") + "k", LabelsPosition = BarLabelPosition.Perpendicular, Foreground = Brushes.Black }); count++; } } }); if (!change) { Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.DataBind, (Action)(() => { DataContext = this; })); } }
public Investments() { InitializeComponent(); HoldersItems = Helpers.Initializer.SetHolders(comboFor, this); date_month_to.SelectedDateChanged -= SelectionChanged; date_month_from.SelectedDateChanged -= SelectionChanged; Helpers.Initializer.SetDates(date_month_from, date_month_to); date_month_to.SelectedDateChanged += SelectionChanged; date_month_from.SelectedDateChanged += SelectionChanged; Categories.ItemsSource = InvestmentCategory.Getcategories(); var dateConfig = Mappers.Xy <DateModel>() .X(dateModel => dateModel.DateTime.AddDays(-13).Ticks / (TimeSpan.FromDays(1).Ticks * 30.44)) .Y(dateModel => dateModel.Value); //save the mapper globally. Charting.For <DateModel>(dateConfig); GainFormatter = value => value.ToString(gainformatter); CurrencyFormatter = value => value.ToString("C0"); CurrencyFormatter2 = value => value.ToString(order_history_formatter); MonthFormatter = value => new DateTime((long)((value < 0 ? 0 : value) * TimeSpan.FromDays(1).Ticks * 30.44)).AddDays(13).ToString("MMM yy"); DayFormatter = value => new DateTime((long)((value < 0 ? 0 : value) * TimeSpan.FromDays(1).Ticks * 30.44)).AddDays(13).ToString("M/d/yy"); Task.Factory.StartNew(() => { DataGridInvestments.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged; FillDataGrid(null); }); Task.Factory.StartNew(() => { Gains_Chart(); }); Task.Factory.StartNew(() => { Stacked_Chart(); }); Task.Factory.StartNew(() => { StackedAsset_Chart(); }); Task.Factory.StartNew(() => { PriceAsset_Chart(); }); }