//
// Copyright (c) 2016, MindFusion LLC - Bulgaria.
//

using System;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Windows.Forms;

using MindFusion.Spreadsheet;


namespace MindFusion.Spreadsheet.WinForms.Samples.CS.Charts
{
	public partial class MainForm : Form
	{
		public MainForm()
		{
			InitializeComponent();

			var chartsSheet = workbook.Worksheets[0];
			var dataSheet = workbook.Worksheets[1];

			dataSheet.BeginInit();
			for (int c = 1; c <= 5; c++)
				dataSheet.Cells[c, 0].Data = string.Format("Column {0}", c);
			for (int r = 1; r <= 5; r++)
				dataSheet.Cells[0, r].Data = string.Format("Row {0}", r);
			for (int c = 1; c <= 5; c++)
				for (int r = 1; r <= 5; r++)
					dataSheet.Cells[c, r].Data = rnd.Next(0, 100);
			dataSheet.EndInit();

			chartsSheet.BeginInit();
			var cell = chartsSheet.Cells[0, 0];
			cell.Data = "Column chart";
			var chart = chartsSheet.Drawing.AddChart(0, 1);
			chart.Type = MindFusion.Spreadsheet.Charts.ChartType.Column;
			chart.SetDataSource("Data!A1:F6", MindFusion.Spreadsheet.Charts.PlotBy.Column, true, true);

			cell = chartsSheet.Cells[9, 0];
			cell.Data = "Bar chart";
			chart = chartsSheet.Drawing.AddChart(9, 1);
			chart.Type = MindFusion.Spreadsheet.Charts.ChartType.Bar;
			chart.SetDataSource("Data!A1:F6", MindFusion.Spreadsheet.Charts.PlotBy.Column, true, true);
			
			cell = chartsSheet.Cells[0, 19];
			cell.Data = "Line chart with marks";
			chart = chartsSheet.Drawing.AddChart(0, 20);
			chart.Type = MindFusion.Spreadsheet.Charts.ChartType.LineWithMarks;
			chart.SetDataSource("Data!A1:F6", MindFusion.Spreadsheet.Charts.PlotBy.Column, true, true);

			cell = chartsSheet.Cells[9, 19];
			cell.Data = "Stacked area chart";
			chart = chartsSheet.Drawing.AddChart(9, 20);
			chart.Type = MindFusion.Spreadsheet.Charts.ChartType.AreaStacked;
			chart.SetDataSource("Data!A1:F6", MindFusion.Spreadsheet.Charts.PlotBy.Column, true, true);

			cell = chartsSheet.Cells[0, 38];
			cell.Data = "Scatter chart with smooth marks";
			chart = chartsSheet.Drawing.AddChart(0, 39);
			chart.Type = MindFusion.Spreadsheet.Charts.ChartType.ScatterWithSmoothLinesAndMarks;
			chart.SetDataSource("Data!A1:F6", MindFusion.Spreadsheet.Charts.PlotBy.Column, true, true);

			cell = chartsSheet.Cells[9, 38];
			cell.Data = "Pie chart";
			chart = chartsSheet.Drawing.AddChart(9, 39);
			chart.Type = MindFusion.Spreadsheet.Charts.ChartType.Pie;
			chart.SetDataSource("Data!A1:F6", MindFusion.Spreadsheet.Charts.PlotBy.Column, true, true);

			cell = chartsSheet.Cells[0, 57];
			cell.Data = "Filled radar chart";
			chart = chartsSheet.Drawing.AddChart(0, 58);
			chart.Type = MindFusion.Spreadsheet.Charts.ChartType.RadarFilled;
			chart.SetDataSource("Data!A1:F6", MindFusion.Spreadsheet.Charts.PlotBy.Column, true, true);

			cell = chartsSheet.Cells[9, 57];
			cell.Data = "Bubble chart";
			chart = chartsSheet.Drawing.AddChart(9, 58);
			chart.Type = MindFusion.Spreadsheet.Charts.ChartType.Bubble;
			chart.SetDataSource("Data!A1:F6", MindFusion.Spreadsheet.Charts.PlotBy.Column, true, true);

			foreach (var c in chartsSheet.Drawing.Charts)
			{
				c.HorizontalOffset = Measure.Point(2);
				c.VerticalOffset = Measure.Point(1);
				c.Width = Measure.Point(400);
				c.Height = Measure.Point(250);
				c.LineColor = Color.Navy;
				c.LineSize = Measure.Point(1);
			}

			chartsSheet.EndInit();
		}

		private static readonly Random rnd = new Random(DateTime.Now.Millisecond);
	}
}
