//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet worksheet = workbook.Worksheets[0]; worksheet.Range["A2:A6"].NumberFormat = "m/d/yyyy"; // set data worksheet.Range["A1:D6"].Value = new object[,] { {null, "S1", "S2", "S3"}, {new DateTime(2015, 10, 7), 10, 25, 25}, {new DateTime(2015, 10, 24), 51, 36, 27}, {new DateTime(2015, 11, 8), 52, 85, 30}, {new DateTime(2015, 11, 25), 22, 65, 65}, {new DateTime(2015, 12, 10), 23, 69, 69} }; // set columns width to display data worksheet.Columns[0].AutoFit(); // add chart GrapeCity.Documents.Excel.Drawing.IShape shape = worksheet.Shapes.AddChart(GrapeCity.Documents.Excel.Drawing.ChartType.ColumnClustered, 250, 20, 360, 230); shape.Chart.SeriesCollection.Add(worksheet.Range["A1:D6"], GrapeCity.Documents.Excel.Drawing.RowCol.Columns, true, true); GrapeCity.Documents.Excel.Drawing.IAxis categoryAxis = shape.Chart.Axes.Item(GrapeCity.Documents.Excel.Drawing.AxisType.Category); // config axis maximum and minimum scale categoryAxis.MaximumScale = new DateTime(2015, 12, 20).ToOADate(); categoryAxis.MinimumScale = new DateTime(2015, 10, 1).ToOADate(); // config axis units categoryAxis.BaseUnit = GrapeCity.Documents.Excel.Drawing.TimeUnit.Months; categoryAxis.MajorUnitScale = GrapeCity.Documents.Excel.Drawing.TimeUnit.Months; categoryAxis.MajorUnit = 1; categoryAxis.MinorUnitScale = GrapeCity.Documents.Excel.Drawing.TimeUnit.Days; categoryAxis.MinorUnit = 15; // Save to an excel file workbook.Save("ConfigCategoryAxisUnits.xlsx");
' Create a new Workbook Dim workbook As New Workbook Dim worksheet As IWorksheet = workbook.Worksheets(0) worksheet.Range("A2:A6").NumberFormat = "m/d/yyyy" ' set data worksheet.Range("A1:D6").Value = New Object(,) { {Nothing, "S1", "S2", "S3"}, {New DateTime(2015, 10, 7), 10, 25, 25}, {New DateTime(2015, 10, 24), 51, 36, 27}, {New DateTime(2015, 11, 8), 52, 85, 30}, {New DateTime(2015, 11, 25), 22, 65, 65}, {New DateTime(2015, 12, 10), 23, 69, 69} } ' set columns width to display data worksheet.Columns(0).AutoFit() ' add chart Dim shape As GrapeCity.Documents.Excel.Drawing.IShape = worksheet.Shapes.AddChart(GrapeCity.Documents.Excel.Drawing.ChartType.ColumnClustered, 250, 20, 360, 230) shape.Chart.SeriesCollection.Add(worksheet.Range("A1:D6"), GrapeCity.Documents.Excel.Drawing.RowCol.Columns, True, True) Dim categoryAxis As GrapeCity.Documents.Excel.Drawing.IAxis = shape.Chart.Axes.Item(GrapeCity.Documents.Excel.Drawing.AxisType.Category) ' config axis maximum and minimum scale categoryAxis.MaximumScale = New DateTime(2015, 12, 20).ToOADate() categoryAxis.MinimumScale = New DateTime(2015, 10, 1).ToOADate() ' config axis units categoryAxis.BaseUnit = GrapeCity.Documents.Excel.Drawing.TimeUnit.Months categoryAxis.MajorUnitScale = GrapeCity.Documents.Excel.Drawing.TimeUnit.Months categoryAxis.MajorUnit = 1 categoryAxis.MinorUnitScale = GrapeCity.Documents.Excel.Drawing.TimeUnit.Days categoryAxis.MinorUnit = 15 ' save to an excel file workbook.Save("ConfigCategoryAxisUnits.xlsx")