using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Demo.Models;
using Telerik.Web.UI;

namespace Demo._2_Chart
{
    public partial class dateAxis : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadChartData();

            FormatChart();
        
        }
  
        /// <summary>
        /// Loads the chart data.
        /// </summary>
        private void LoadChartData()
        {

            var ctx = new StockContext();
            var positions = ctx.Positions.OrderByDescending(p => p.Date).Take(10).OrderBy(p => p.Date).ToArray();
            chart.DataSource = positions;
            chart.DataBind();

        }
  
        private void FormatChart()
        {

            // Format the series
            var series = new ScatterLineSeries();
            series.Name = "Closing Stock Prices";
            series.DataFieldY = "Close";
            series.DataFieldX = "Date";
            series.LabelsAppearance.DataFormatString = "{1:$0.00}";
            series.TooltipsAppearance.DataFormatString = "{1:$0.00} on {0:m}";
            chart.PlotArea.Series.Add(series);

            // Format the series
            var series2 = new ScatterLineSeries();
            series2.Name = "Opening Stock Prices";
            series2.DataFieldY = "Open";
            series2.DataFieldX = "Date";
            series2.LabelsAppearance.DataFormatString = "{1:$0.00}";
            series2.TooltipsAppearance.DataFormatString = "{1:$0.00} on {0:m}";
            chart.PlotArea.Series.Add(series2);

            // X-axis
            chart.PlotArea.XAxis.LabelsAppearance.DataFormatString = "m";
            chart.PlotArea.XAxis.TitleAppearance.Text = "Closing Date";

            // Y-axis
            chart.PlotArea.YAxis.TitleAppearance.Text = "Closing Price";
            chart.PlotArea.YAxis.LabelsAppearance.DataFormatString = "$0.00";
        }
    }

}