using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Telerik.UI.Xaml.Controls.Chart;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace CustomDrillDown
{
    public sealed partial class MainPage : Page
    {
        public Random Rand = new Random();
        List<YearData> chartData;
        public MainPage()
        {
            this.InitializeComponent();

            chartData = new List<YearData>();
            for (int i = 0; i < 5; i++)
            {
                YearData data = new YearData();
                data.Category = (2010 + i).ToString();
                for (int j = 1; j <= 12; j++)
                {
                    MonthData mdata = new MonthData();
                    mdata.Category = j.ToString();
                    mdata.Value = Rand.Next(100);
                    data.MonthDataList.Add(mdata);
                }

                chartData.Add(data);
            }

            this.chart.DataContext = chartData;
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void ChartSelectionBehavior_SelectionChanged(object sender, EventArgs e)
        {
            var behavior = sender as ChartSelectionBehavior;
            var chart = behavior.Chart as RadCartesianChart;
            var yearData = behavior.SelectedPoints.FirstOrDefault().DataItem as YearData;
            if (yearData != null)
            {
                chart.Series[0].ItemsSource = yearData.MonthDataList;
            }
        }

        private void btn_Click(object sender, RoutedEventArgs e)
        {
            this.chart.Series[0].ItemsSource = chartData;
        }
    }
}
