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.Charting;

namespace DataSeriesAddInsert
{
    public partial class MainPage : UserControl
    {
        DataSeries series = new DataSeries();
        DataSeries series2 = new DataSeries();
        DataPoint newPoint = new DataPoint(new DateTime(2009, 5, 7).ToOADate(), 110);

        public MainPage()
        {
            InitializeComponent();

            series.Definition = new SplineSeriesDefinition();
            series.LegendLabel = "Product Sales Q1";
            series.Add(new DataPoint(new DateTime(2009, 5, 1).ToOADate(), 138));
            series.Add(new DataPoint(new DateTime(2009, 5, 2).ToOADate(), 143));
            series.Add(new DataPoint(new DateTime(2009, 5, 3).ToOADate(), 120));
            series.Add(new DataPoint(new DateTime(2009, 5, 4).ToOADate(), 135));
            series.Add(new DataPoint(new DateTime(2009, 5, 5).ToOADate(), 125));

            series2.Definition = new SplineSeriesDefinition();
            series2.LegendLabel = "Product Sales Q2";
            series2.Add(new DataPoint(new DateTime(2009, 5, 1).ToOADate(), 35));
            series2.Add(new DataPoint(new DateTime(2009, 5, 2).ToOADate(), 45));
            series2.Add(new DataPoint(new DateTime(2009, 5, 3).ToOADate(), 55));
            series2.Add(new DataPoint(new DateTime(2009, 5, 4).ToOADate(), 15));
            series2.Add(new DataPoint(new DateTime(2009, 5, 5).ToOADate(), 25));
            //add new DataPoint(10, 110); 
            series2.Add(newPoint);

            radChart.DefaultView.ChartArea.AxisX.IsDateTime = true;
            radChart.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Inside;
            radChart.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;
            radChart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MMM";

            radChart.DefaultView.ChartTitle.Content = "Year 2009";
            radChart.DefaultView.ChartLegend.Header = "Legend";
            radChart.DefaultView.ChartLegend.UseAutoGeneratedItems = true;
            //Axis X
            radChart.DefaultView.ChartArea.AxisX.Title = "Month";
            //radChart.DefaultView.ChartArea.AxisX.AutoRange = false;
            //radChart.DefaultView.ChartArea.AxisX.MinValue = 1;
            //radChart.DefaultView.ChartArea.AxisX.MaxValue = 12;
            //radChart.DefaultView.ChartArea.AxisX.Step = 1;
            radChart.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Between;
            //Axis Y
            radChart.DefaultView.ChartArea.AxisY.Title = "Quantity";

            radChart.DefaultView.ChartArea.DataSeries.Add(series);
            radChart.DefaultView.ChartArea.DataSeries.Add(series2);
        }


        private void btnInsert_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;

            if ((bool)button.IsPressed)
            {
                DataPoint point = new DataPoint(new DateTime(2009, 5, 7).ToOADate(), 25);
                series2.Insert(6, point);
                series2.RemoveAt(0);
            }
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;

            if ((bool)button.IsPressed)
            {
                DataPoint point = new DataPoint(new DateTime(2009, 5, 10).ToOADate(), 35);
                series2.RemoveAt(0);
                series2.Add(point);
            }
        }

        private void btnRemove_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;

            if ((bool)button.IsPressed)
            {
                series2.Remove(newPoint);
            }
        }
    }
}
