Interface IChartCategoryAxis
Represents category axis of the chart.
Inherited Members
Namespace: Syncfusion.XlsIO
Assembly: Syncfusion.XlsIO.UWP.dll
Syntax
public interface IChartCategoryAxis : IChartValueAxis, IChartAxis
Properties
AutoTickLabelSpacing
Gets or sets whether or not the tick label spacing is automatic.
Declaration
bool AutoTickLabelSpacing { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to access AutoTickLabelSpacing property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["D1"].Text = "Apr";
sheet.Range["E1"].Text = "May";
sheet.Range["F1"].Text = "Jun";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["D2"].Value = "30";
sheet.Range["E2"].Value = "20";
sheet.Range["F2"].Value = "10";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:F2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set tick label spacing
categoryAxis.TickLabelSpacing = 2;
//Check auto spacing
Console.Write(categoryAxis.AutoTickLabelSpacing);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//False
BaseUnit
Gets or sets the base unit for the IChartCategoryAxis.
Declaration
ExcelChartBaseUnit BaseUnit { get; set; }
Property Value
Type |
---|
ExcelChartBaseUnit |
Examples
The following code illustrates how to set BaseUnit for IChartCategoryAxis.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].DateTime = new System.DateTime(2017, 3, 15);
sheet.Range["B1"].DateTime = new System.DateTime(2017, 9, 17);
sheet.Range["C1"].DateTime = new System.DateTime(2017, 5, 2);
sheet.Range["D1"].DateTime = new System.DateTime(2016, 5, 2);
sheet.Range["E1"].DateTime = new System.DateTime(2015, 5, 2);
sheet.Range["F1"].DateTime = new System.DateTime(2011, 5, 2);
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["D2"].Value = "30";
sheet.Range["E2"].Value = "20";
sheet.Range["F2"].Value = "10";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:F2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set category type
categoryAxis.CategoryType = ExcelCategoryType.Time;
//Set base unit
categoryAxis.BaseUnit = ExcelChartBaseUnit.Year;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
BaseUnitIsAuto
True to use automatic base units for the specified category axis. otherwise False.
Declaration
bool BaseUnitIsAuto { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
The following code illustrates how to access BaseUnitIsAuto property.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].DateTime = new System.DateTime(2017, 3, 15);
sheet.Range["B1"].DateTime = new System.DateTime(2017, 9, 17);
sheet.Range["C1"].DateTime = new System.DateTime(2017, 5, 2);
sheet.Range["D1"].DateTime = new System.DateTime(2016, 5, 2);
sheet.Range["E1"].DateTime = new System.DateTime(2015, 5, 2);
sheet.Range["F1"].DateTime = new System.DateTime(2011, 5, 2);
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["D2"].Value = "30";
sheet.Range["E2"].Value = "20";
sheet.Range["F2"].Value = "10";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:F2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set category type
categoryAxis.CategoryType = ExcelCategoryType.Time;
//Set base unit
categoryAxis.BaseUnit = ExcelChartBaseUnit.Year;
//Check base unit auto or not
Console.Write(categoryAxis.BaseUnitIsAuto);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//False
BinWidth
Get or Set the number of data points in each range.
Declaration
double BinWidth { get; set; }
Property Value
Type |
---|
System.Double |
Remarks
Examples
The following code illustrates how to set the grouping width for Histogram and Pareto charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set chart type
chart.ChartType = ExcelChartType.Pareto;
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set category axis bin width
categoryAxis.BinWidth = 7;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
CategoryLabels
Gets or sets the category labels for the chart.
Declaration
IRange CategoryLabels { get; set; }
Property Value
Type |
---|
IRange |
Examples
The following code illustrates how to access the category labels range.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Get category label range
Console.WriteLine(categoryAxis.CategoryLabels.AddressLocal);
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
Console.ReadKey();
}
//Output will be
//A1:C1
CategoryType
Gets or sets the category type.
Declaration
ExcelCategoryType CategoryType { get; set; }
Property Value
Type |
---|
ExcelCategoryType |
Examples
By default CategoryType is set to Automatic. Here for example, we set Time to CategoryType.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].DateTime = new System.DateTime(2017, 3, 15);
sheet.Range["B1"].DateTime = new System.DateTime(2017, 9, 17);
sheet.Range["C1"].DateTime = new System.DateTime(2017, 5, 2);
sheet.Range["D1"].DateTime = new System.DateTime(2016, 5, 2);
sheet.Range["E1"].DateTime = new System.DateTime(2015, 5, 2);
sheet.Range["F1"].DateTime = new System.DateTime(2011, 5, 2);
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["D2"].Value = "30";
sheet.Range["E2"].Value = "20";
sheet.Range["F2"].Value = "10";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:F2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set category type
categoryAxis.CategoryType = ExcelCategoryType.Time;
//Set base unit
categoryAxis.BaseUnit = ExcelChartBaseUnit.Year;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
EnteredDirectlyCategoryLabels
Gets or sets the directly entered category labels for the chart.
Declaration
object[] EnteredDirectlyCategoryLabels { get; set; }
Property Value
Type |
---|
System.Object[] |
Examples
The following code illustrates how to set category labels directly for charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set category labels directly
categoryAxis.EnteredDirectlyCategoryLabels = new object[] { "Oct", "Nov", "Dec" };
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
HasAutomaticBins
True if bins generated are automatic. otherwise False
Declaration
bool HasAutomaticBins { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
Examples
By default HasAutomaticBins is set to "false" so grouping will be done based on the categories in the IChartCategoryAxis. Here for example, we set HasAutomaticBins to "true" so that chart serie would be grouped automatically.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set chart type
chart.ChartType = ExcelChartType.Pareto;
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set bins to automatic
categoryAxis.HasAutomaticBins = true;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
IsBetween
True to cut unused plot area. otherwise False. Default for area and surface charts.
Declaration
bool IsBetween { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
By default IsBetween is set to "true" so chart serie will be plotted in between the tick marks. Here for example, we set IsBetween to "false" so that chart serie would be plotted on the tick marks.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set category axis IsBetween
categoryAxis.IsBetween = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
IsBinningByCategory
True if bins generated by category values. otherwise False
Declaration
bool IsBinningByCategory { get; set; }
Property Value
Type |
---|
System.Boolean |
Remarks
Examples
By default IsBinningByCategory is set to "true" so chart serie are grouped based on category labels. Here for example, we set "false" to IsBinningByCategory so that chart serie would be grouped automatically.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set chart type
chart.ChartType = ExcelChartType.Pareto;
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set bins to automatic
categoryAxis.IsBinningByCategory = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
LabelFrequency
Gets or sets the number of categories or series between tick-mark labels.
Declaration
int LabelFrequency { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
This property is obsolete. Please use TickLabelSpacing instead of it
MajorUnitScale
Gets or sets the major unit scale value for the IChartCategoryAxis when the CategoryType of the axis is set to Time.
Declaration
ExcelChartBaseUnit MajorUnitScale { get; set; }
Property Value
Type |
---|
ExcelChartBaseUnit |
Examples
The following code illustrates how to set major unit scale value for IChartCategoryAxis.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].DateTime = new System.DateTime(2017, 3, 15);
sheet.Range["B1"].DateTime = new System.DateTime(2017, 9, 17);
sheet.Range["C1"].DateTime = new System.DateTime(2017, 5, 2);
sheet.Range["D1"].DateTime = new System.DateTime(2016, 5, 2);
sheet.Range["E1"].DateTime = new System.DateTime(2015, 5, 2);
sheet.Range["F1"].DateTime = new System.DateTime(2015, 5, 7);
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["D2"].Value = "30";
sheet.Range["E2"].Value = "20";
sheet.Range["F2"].Value = "10";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:F2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set category type
categoryAxis.CategoryType = ExcelCategoryType.Time;
//Set major and minor units
categoryAxis.MajorUnitScale = ExcelChartBaseUnit.Year;
categoryAxis.MinorUnitScale = ExcelChartBaseUnit.Month;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
MinorUnitScale
Gets or sets the minor unit scale value for the IChartCategoryAxis when the CategoryType of the axis is set to Time.
Declaration
ExcelChartBaseUnit MinorUnitScale { get; set; }
Property Value
Type |
---|
ExcelChartBaseUnit |
Examples
The following code illustrates how to set minor unit scale value for IChartCategoryAxis.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].DateTime = new System.DateTime(2017, 3, 15);
sheet.Range["B1"].DateTime = new System.DateTime(2017, 9, 17);
sheet.Range["C1"].DateTime = new System.DateTime(2017, 5, 2);
sheet.Range["D1"].DateTime = new System.DateTime(2016, 5, 2);
sheet.Range["E1"].DateTime = new System.DateTime(2015, 5, 2);
sheet.Range["F1"].DateTime = new System.DateTime(2015, 5, 7);
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["D2"].Value = "30";
sheet.Range["E2"].Value = "20";
sheet.Range["F2"].Value = "10";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:F2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set category type
categoryAxis.CategoryType = ExcelCategoryType.Time;
//Set major and minor units
categoryAxis.MajorUnitScale = ExcelChartBaseUnit.Year;
categoryAxis.MinorUnitScale = ExcelChartBaseUnit.Month;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
NoMultiLevelLabel
True if multi-Level category axis is not allowed. otherwise False.
Declaration
bool NoMultiLevelLabel { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
By default
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Text = "Apr";
sheet.Range["B2"].Text = "May";
sheet.Range["C2"].Text = "Jun";
sheet.Range["A4"].Value = "10";
sheet.Range["B4"].Value = "20";
sheet.Range["C4"].Value = "30";
sheet.Range["A3"].Value = "15";
sheet.Range["B3"].Value = "10";
sheet.Range["C3"].Value = "35";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C4"];
//Set chart type
chart.ChartType = ExcelChartType.Line;
//Set NoMultiLevelLabel
chart.PrimaryCategoryAxis.NoMultiLevelLabel = false;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
NumberOfBins
Gets / Sets the Number of Bins in the axis
Declaration
int NumberOfBins { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
Examples
The following code illustrates how to set number of bins in the chart axis for Histogram and Pareto charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set chart type
chart.ChartType = ExcelChartType.Pareto;
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set category axis bins
categoryAxis.NumberOfBins = 2;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
Offset
Gets or sets the distance between the labels and the axis line. The value can be from 0 through 1000.
Declaration
int Offset { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
By default the category labels are separated by a distance of "100" from the IChartCategoryAxis. Here for example, we set "350" to Offset to increase the distance to "350" from "100".
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set category axis Offset
categoryAxis.Offset = 350;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
OverflowBinValue
Get or Set the OverFlow Bin value
Declaration
double OverflowBinValue { get; set; }
Property Value
Type |
---|
System.Double |
Remarks
Examples
The following code illustrates how to set OverflowBinValue for Histogram and Pareto charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set chart type
chart.ChartType = ExcelChartType.Pareto;
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set bin to automatic
categoryAxis.HasAutomaticBins = true;
//Set bin overflow
categoryAxis.OverflowBinValue = 25;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
TickLabelSpacing
Gets or sets the number of categories or series between tick-mark labels. Applies only to category and series axes. Can be a value from 1 through 31999.
Declaration
int TickLabelSpacing { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to set TickLabelSpacing for chart axis.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["D1"].Text = "Apr";
sheet.Range["E1"].Text = "May";
sheet.Range["F1"].Text = "Jun";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["D2"].Value = "30";
sheet.Range["E2"].Value = "20";
sheet.Range["F2"].Value = "10";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:F2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set tick label spacing
categoryAxis.TickLabelSpacing = 2;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
TickMarksFrequency
Gets or sets the number of categories or series between tick marks.
Declaration
int TickMarksFrequency { get; set; }
Property Value
Type |
---|
System.Int32 |
Remarks
This property is obsolete. Please use TickMarkSpacing instead of it
TickMarkSpacing
Gets or sets the number of categories or series between tick marks. Applies only to category and series axes. Can be a value from 1 through 31999.
Declaration
int TickMarkSpacing { get; set; }
Property Value
Type |
---|
System.Int32 |
Examples
The following code illustrates how to set TickMarkSpacing for chart axis.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["D1"].Text = "Apr";
sheet.Range["E1"].Text = "May";
sheet.Range["F1"].Text = "Jun";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
sheet.Range["D2"].Value = "30";
sheet.Range["E2"].Value = "20";
sheet.Range["F2"].Value = "10";
//Create chart
IChart chart = sheet.Charts.Add();
//Set range
chart.DataRange = sheet.Range["A1:F2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set tick mark spacing
categoryAxis.TickMarkSpacing = 2;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}
UnderflowBinValue
Get or Set the UnderFlow Bin value
Declaration
double UnderflowBinValue { get; set; }
Property Value
Type |
---|
System.Double |
Remarks
Examples
The following code illustrates how to set UnderflowBinValue for Histogram and Pareto charts.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Create worksheet
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Add data
sheet.Range["A1"].Text = "Jan";
sheet.Range["B1"].Text = "Feb";
sheet.Range["C1"].Text = "Mar";
sheet.Range["A2"].Value = "10";
sheet.Range["B2"].Value = "20";
sheet.Range["C2"].Value = "30";
//Create chart
IChart chart = sheet.Charts.Add();
//Set chart type
chart.ChartType = ExcelChartType.Pareto;
//Set range
chart.DataRange = sheet.Range["A1:C2"];
//Set chart category axis
IChartCategoryAxis categoryAxis = chart.PrimaryCategoryAxis;
//Set bin to automatic
categoryAxis.HasAutomaticBins = true;
//Set bin underflow
categoryAxis.UnderflowBinValue = 12;
//Save and Dispose
workbook.SaveAs("Chart.xlsx");
workbook.Close();
}