using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Charting;

namespace StackedBars_AxisXLabels
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            this.FillSampleChartData();

            List<User> data = new List<User>();
            data.Add(new User("Stock Ordered", 20, 37, 56, 67));
            data.Add(new User("Stock Processed", 55, 120, 201, 33));
            data.Add(new User("Stock Shipped", 23, 49, 55, 66));
            data.Add(new User("Stock delivered", 47, 27, 103, 91));

            this.RadChart1.ItemsSource = data;
        }
        private void FillSampleChartData()
        {
            SeriesMapping sm1 = new SeriesMapping();
            StackedBarSeriesDefinition bar1 = new StackedBarSeriesDefinition();
            bar1.StackGroupName = "Stack 1";
            sm1.SeriesDefinition = bar1;
            sm1.LegendLabel = "Value1";
            ItemMapping im1 = new ItemMapping();
            im1.DataPointMember = DataPointMember.YValue;
            im1.FieldName = "Value1";
            sm1.ItemMappings.Add(im1);
            im1 = new ItemMapping();
            im1.DataPointMember = DataPointMember.XCategory;
            im1.FieldName = "Name";
            sm1.ItemMappings.Add(im1);

            SeriesMapping sm2 = new SeriesMapping();
            StackedBarSeriesDefinition bar2 = new StackedBarSeriesDefinition() { ItemLabelFormat = "#STSUM" };
            bar2.StackGroupName = "Stack 1";
            sm2.SeriesDefinition = bar2;
            sm2.LegendLabel = "Value2";
            ItemMapping im2 = new ItemMapping();
            im2.DataPointMember = DataPointMember.YValue;
            im2.FieldName = "Value2";
            sm2.ItemMappings.Add(im2);
            im2 = new ItemMapping();
            im2.DataPointMember = DataPointMember.XCategory;
            im2.FieldName = "Name";
            sm2.ItemMappings.Add(im2);

            SeriesMapping sm3 = new SeriesMapping();
            StackedBarSeriesDefinition bar3 = new StackedBarSeriesDefinition();
            bar3.StackGroupName = "Stack 1";
            sm3.SeriesDefinition = bar3;
            sm3.LegendLabel = "Value3";
            ItemMapping im3 = new ItemMapping();
            im3.DataPointMember = DataPointMember.YValue;
            im3.FieldName = "Value3";
            sm3.ItemMappings.Add(im3);
            im3 = new ItemMapping();
            im3.DataPointMember = DataPointMember.XCategory;
            im3.FieldName = "Name";
            sm3.ItemMappings.Add(im3);

            SeriesMapping sm4 = new SeriesMapping();
            StackedBarSeriesDefinition bar4 = new StackedBarSeriesDefinition();
            bar4.StackGroupName = "Stack 2";
            sm4.SeriesDefinition = bar4;
            sm4.LegendLabel = "Value4";
            ItemMapping im4 = new ItemMapping();
            im4.DataPointMember = DataPointMember.YValue;
            im4.FieldName = "Value4";
            sm4.ItemMappings.Add(im4);
            im4 = new ItemMapping();
            im4.DataPointMember = DataPointMember.XCategory;
            im4.FieldName = "Name";
            sm4.ItemMappings.Add(im4);

            RadChart1.SeriesMappings.Add(sm1);
            RadChart1.SeriesMappings.Add(sm2);
            RadChart1.SeriesMappings.Add(sm3);
            RadChart1.SeriesMappings.Add(sm4);
        }

        public class User
        {
            public User(string name, double value1, double value2, double value3, double value4)
            {
                this.Name = name;
                this.Value1 = value1;
                this.Value2 = value2;
                this.Value3 = value3;
                this.Value4 = value4;
            }
            public string Name
            {
                get;
                set;
            }
            public double Value1
            {
                get;
                set;
            }
            public double Value2
            {
                get;
                set;
            }
            public double Value3
            {
                get;
                set;
            }
            public double Value4
            {
                get;
                set;
            }
        }
    }
}
