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.Data;
using System.Collections.ObjectModel;

namespace FilterChart_CompositeFilterDescriptor
{
    public partial class MainPage : UserControl
    {
        CompositeFilterDescriptor chartFilterDescriptorCol = new CompositeFilterDescriptor();
        public MainPage()
        {
            InitializeComponent();
            RadChart1.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "ddd\ndd.MM";

            MyDataContext context = new MyDataContext();

            this.DataContext = context;
        }

        private void GridView1_Filtered(object sender, Telerik.Windows.Controls.GridView.GridViewFilteredEventArgs e)
        {
            this.RadChart1.FilterDescriptors.Clear();

            foreach (IFilterDescriptor descriptor in this.GridView1.FilterDescriptors)
            {
                this.RadChart1.FilterDescriptors.Add(descriptor);
            }
        }
    }

    public class MyDateObject
    {
        public double SampleValue { get; set; }
        public DateTime Date { get; set; }
    }

    public class MyDataContext
    {
        public const int min = 20;
        public const int max = 80;
        public ObservableCollection<MyDateObject> List { get; set; }
        Random r = new Random();
        DateTime baseDate = DateTime.Today;

        public MyDataContext()
        {
            this.CreateChartData();
        }

        private void CreateChartData()
        {
            List = new ObservableCollection<MyDateObject>();
            for (int i = 0; i < 15; i++)
            {
                List.Add(new MyDateObject() { SampleValue = r.Next(min, max), Date = baseDate.AddDays(i) });
            }
        }
    }
}
