hi,
I want to format the x-axis of chart. My chart has lot of points for x-axis so I want to set the major unit to automatic. I tried this at the design time but does not help.
So I tried below code to make major and minor unit to automatic.
-----------------------------------------------------------------------------------------------
Workbook oWB = new Workbook(@"C:\Test.xls");
Cells oCells = oWB.Worksheets[0].Cells;
Worksheet oSheet = oWB.Worksheets[0];
DataTable dt = CreateDataTable();
oCells.ImportDataTable(dt, false, 2, 0, dt.Rows.Count, dt.Columns.Count, false, "MM/dd/yyyy", true);
Aspose.Cells.Charts.Chart oChart = oSheet.Charts["Chart 1"];
oChart.CategoryAxis.IsAutomaticMajorUnit = true;
oChart.CategoryAxis.IsAutomaticMinorUnit = true;
oChart.CategoryAxis.BaseUnitScale = Aspose.Cells.Charts.TimeUnit.Months;
oWB.Save(@"C:\TestOuput.xls");
private DataTable CreateDataTable()
{
DataTable dt = new DataTable("Test Data");
DataColumn dcDate = new DataColumn("Date", typeof(System.DateTime));
DataColumn dcV1 = new DataColumn("V1", typeof(System.Double));
DataColumn dcV2 = new DataColumn("V2", typeof(System.Double));
DataColumn dcV3 = new DataColumn("V3", typeof(System.Double));
DataColumn dcV4 = new DataColumn("V4", typeof(System.Double));
DataColumn dcV5 = new DataColumn("V5", typeof(System.Double));
dt.Columns.Add(dcDate);
dt.Columns.Add(dcVAMI1);
dt.Columns.Add(dcVAMI2);
dt.Columns.Add(dcVAMI3);
dt.Columns.Add(dcVAMI4);
dt.Columns.Add(dcVAMI5);
DateTime dtStartDate = new DateTime(2000, 1, 1);
for (int iCtr = 0; iCtr < 279; iCtr++)
{
DataRow dr = dt.NewRow();
dr[0] = dtStartDate.AddDays(iCtr);
dr[1] = Convert.ToDouble(string.Concat(iCtr + 1, ".", 1));
dr[2] = Convert.ToDouble(string.Concat(iCtr + 1, ".", 2));
dr[3] = Convert.ToDouble(string.Concat(iCtr + 1, ".", 3));
dr[4] = Convert.ToDouble(string.Concat(iCtr + 1, ".", 4));
dr[5] = Convert.ToDouble(string.Concat(iCtr + 1, ".", 5));
dt.Rows.Add(dr);
}
dt.AcceptChanges();
return dt;
}
-----------------------------------------------------------------------------------------------
Attached the template and the output file.