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 _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            BindDataToChart();

        }

        private void BindDataToChart()
        {

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

            var series = new CandlestickSeries();

            var xAxis = chart.PlotArea.XAxis;
            xAxis.TitleAppearance.Text = "Date";

            foreach (var pos in positions)
            {
                series.SeriesItems.Add(new CandlestickSeriesItem(pos.Open, pos.Close, pos.High, pos.Low));
                xAxis.Items.Add(pos.Date.ToString("d-MMM"));
            }

            chart.PlotArea.YAxis.LabelsAppearance.DataFormatString = "$0.00";

            chart.PlotArea.Series.Add(series);

        
        }
    }
}