using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using C1.Win.Chart;
using System.Drawing.Drawing2D;
using C1.Chart;
using System.IO;

namespace FlexChartExplorer.Samples
{
    public partial class AxisBinding : UserControl
    {
        int npts = 100;
        Random rnd = new Random();

        public AxisBinding()
        {
            InitializeComponent();
            InitilizeControls();

            SetupChart();
        }

        void SetupChart()
        {
            // Create sample financial data
            var data = CreateData();
            
            flexChart1.BeginUpdate();
            flexChart1.Series.Clear();
            flexChart1.DataSource = data;
            flexChart1.ChartType = ChartType.Line;

            var axisDataSource = new List<AxisBindingItem>();
            for (int i = 0; i < 20; i++)
            {
                axisDataSource.Add(new AxisBindingItem()
                {
                    Value = 500 + i * 50,
                    Text = string.Format("$ {0:n0}", 500 + i * 50)
                });
            }

            flexChart1.AxisY.DataSource = axisDataSource;
            flexChart1.AxisY.Binding = "Value,Text";

            var series1 = new Series();
            series1.Binding = "Price";
            series1.BindingX = "Time";
            series1.Name = "Price";
            flexChart1.Series.Add(series1);

            flexChart1.EndUpdate();
        }

        List<Quote> CreateData()
        {
            List<Quote> list = new List<Quote>();
            var dt = DateTime.Today;
            var price = 1000;
            for (var i = 0; i < npts; i++)
            {
                price += rnd.Next(10) % 2 == 0 ? rnd.Next(50) : -rnd.Next(50);
                list.Add(new Quote() { Time = dt.AddDays(i), Price = price });
            }

            return list;
        }

        public class Quote
        {
            public DateTime Time { get; set; }
            public double Price { get; set; }
        }

        public class AxisBindingItem
        {
            public double Value { get; set; }
            public string Text { get; set; }
        }

        private void InitilizeControls()
        {
            flexChart1 = baseSample1.flexChart1;
            baseSample1.lblTitle.Text = Localizer.GetItem("axisBinding", "title");
            baseSample1.tbDescription.Rtf = Localizer.GetItem("axisBinding", "description").MakeRtf();
        }

    }
}
