public ProductTypesSalesChartView(IRegionManager regionManager, IEventAggregator eventAggregator) : base(regionManager, eventAggregator) { InitializeComponent(); StackedBarSeries stackedBarSeries = new StackedBarSeries(); stackedBarSeries.Series.Add(new StackedFragmentSeries()); var stackedFragmentSeries = new StackedFragmentSeries(); stackedFragmentSeries.ValueMemberPath = ""; stackedFragmentSeries.Title = ""; //StackedBarChart.Series }
/// <summary> /// Initializes the Category chart. This chart shows a stack series that breaks down the /// Inflow or outflow by source. /// </summary> private void InitializeCategoryChart() { // Create a BindingList that contains last year, the current month, and last months data. // This will be used as the DataSource for the chart so we can show one stack for each. BindingList <MonthlyData> monthlyDatas = new BindingList <MonthlyData>() { this.lastYearData, this.currentMonthData, this.lastMonthData }; // X Axis // The X Axis is pretty simple. It's the monetary value of the Inflow / Outflow. // #region X Axis var categoryChartChartNumericX = new NumericXAxis(); // Hook FormatLabel so that we can show the values in a more user-friendly format. categoryChartChartNumericX.FormatLabel += new AxisFormatLabelHandler(categoryChartChartNumericX_FormatLabel); #endregion // X Axis // Y Axis // The Y Axis will display the "name" of the item: "last month", "current", or "last year". // #region Y Axis this.categoryChartChartCategoryY = new CategoryYAxis(); this.categoryChartChartCategoryY.DataSource = monthlyDatas; this.categoryChartChartCategoryY.LabelFontFamily = "Verdana"; this.categoryChartChartCategoryY.LabelHorizontalAlignment = Infragistics.Portable.Components.UI.HorizontalAlignment.Left; this.categoryChartChartCategoryY.LabelTextColor = new SolidColorBrush(Color.FromArgb(146, 146, 146)); // This is arbitrary. We will format the label, anyway, so we could use any field here. this.categoryChartChartCategoryY.Label = "Month"; this.categoryChartChartCategoryY.Interval = 1; // Since the text we want to display doesn't exist as a property on the MonthlyData, we need // to hook LabelFormat and return the appropriate text. this.categoryChartChartCategoryY.FormatLabel += new AxisFormatLabelHandler(categoryChartChartCategoryY_FormatLabel); #endregion // Y Axis // Add the axes to the chart. this.crtCategory.Axes.Add(this.categoryChartChartCategoryY); this.crtCategory.Axes.Add(categoryChartChartNumericX); // StackedBarSeries // The way a StackedBarSeries works is that we create the series and then add // a StackedFragmentSeries for each source. // #region StackedBarSeries // Create the StackedBarSeries itself. this.categoryChartStackedBarSeries = new StackedBarSeries(); // Set it's DataSource. this.categoryChartStackedBarSeries.DataSource = monthlyDatas; // Set the X and Y axes. this.categoryChartStackedBarSeries.XAxis = categoryChartChartNumericX; this.categoryChartStackedBarSeries.YAxis = categoryChartChartCategoryY; // Get a string representing whether we are showing inflow or outflow. string flowDirectionString = this.FlowDirection.ToString(); // Loop through each source. Source[] sources = (Source[])Enum.GetValues(typeof(Source)); foreach (Source source in sources) { // Create a new StackedFragmentSeries for this source. var stackedFragmentSeriesForSource = new StackedFragmentSeries(); stackedFragmentSeriesForSource.Title = source.ToString(); stackedFragmentSeriesForSource.Outline = new SolidColorBrush(Color.Transparent); // Call into a method to get the appropriate color for the fragment. stackedFragmentSeriesForSource.Brush = this.GetSourceChartColor(source); // The name of the property on the MonthlyData that we need to use is a combination // of the source and the flow direction. stackedFragmentSeriesForSource.ValueMemberPath = string.Format("{0}{1}", source.ToString(), flowDirectionString); // Add the fragment to the series. this.categoryChartStackedBarSeries.Series.Add(stackedFragmentSeriesForSource); } #endregion // StackedBarSeries // Add the series to the chart. this.crtCategory.Series.Add(this.categoryChartStackedBarSeries); }