using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Syncfusion.XlsIO;
using System.Data.OleDb;
using System.IO;
using System.Drawing;
using System.Collections;
namespace Holod_r_1
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Setting Range for PrimaryXAxis
this.Chart1.PrimaryXAxis.Range.Min = new DateTime(2000, 06, 06, 23, 55, 00);
this.Chart1.PrimaryXAxis.Range.Max = new DateTime(2000, 06, 10, 01, 10, 34);
this.Chart1.PrimaryXAxis.Range.Interval = 6;
System.Collections.Generic.List<DatetimeData> data = new System.Collections.Generic.List<DatetimeData>();
data.Add(new DatetimeData(new DateTime(2000, 06, 07, 23, 55, 00), 10));
data.Add(new DatetimeData(new DateTime(2000, 06, 08, 01, 10, 05), -30));
data.Add(new DatetimeData(new DateTime(2000, 06, 08, 02, 25, 59), 15));
data.Add(new DatetimeData(new DateTime(2000, 06, 08, 03, 40, 45), -65));
data.Add(new DatetimeData(new DateTime(2000, 06, 08, 04, 55, 44), 90));
data.Add(new DatetimeData(new DateTime(2000, 06, 08, 05, 10, 34), 85));
data.Add(new DatetimeData(new DateTime(2000, 06, 08, 06, 55, 00), 10));
data.Add(new DatetimeData(new DateTime(2000, 06, 09, 08, 10, 05), -30));
data.Add(new DatetimeData(new DateTime(2000, 06, 09, 10, 25, 59), 15));
data.Add(new DatetimeData(new DateTime(2000, 06, 09, 12, 40, 45), -65));
data.Add(new DatetimeData(new DateTime(2000, 06, 09, 15, 55, 44), 90));
data.Add(new DatetimeData(new DateTime(2000, 06, 09, 18, 10, 34), 85));
//Binding Datasource to Chart
this.Chart1.DataSource = data;
this.Chart1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Inserts the sample data for the chart
sheet.Range["A1"].Text = "Month";
sheet.Range["B1"].Text = "Product A";
sheet.Range["C1"].Text = "Product B";
//Months
sheet.Range["A2"].Text = "Jan";
sheet.Range["A3"].Text = "Feb";
sheet.Range["A4"].Text = "Mar";
sheet.Range["A5"].Text = "Apr";
sheet.Range["A6"].Text = "May";
//Create a random Data
Random r = new Random();
for (int i = 2; i <= 6; i++)
{
for (int j = 2; j <= 3; j++)
{
sheet.Range[i, j].Number = r.Next(0, 500);
}
}
IChartShape chart = sheet.Charts.Add();
//Set chart type
chart.ChartType = ExcelChartType.Line;
//Set Chart Title
chart.ChartTitle = "Product Sales comparison";
//Set first serie
IChartSerie productA = chart.Series.Add("ProductA");
productA.Values = sheet.Range["B2:B6"];
productA.CategoryLabels = sheet.Range["A2:A6"];
//Set second serie
IChartSerie productB = chart.Series.Add("ProductB");
productB.Values = sheet.Range["C2:C6"];
productB.CategoryLabels = sheet.Range["A2:A6"];
workbook.SaveAs("chart.xlsx", ExcelSaveType.SaveAsXLS, Response, ExcelDownloadType.PromptDialog);
workbook.Close();
excelEngine.Dispose();
}
}
[Serializable]
public class DatetimeData
{
public DatetimeData(DateTime xval, double yvalue1)
{
this.Xvalue = xval;
this.YValue1 = yvalue1;
}
public DateTime Xvalue
{
get;
set;
}
public double YValue1
{
get;
set;
}
}
}