Determine which Axis exists in the Chart
Sometimes, the user needs to know if a particular axis exists in the Chart. For example, he wants to know if a Secondary Value Axis exists inside the chart or not. Some charts like Pie, PieExploded, PiePie, PieBar, Pie3D, Pie3DExploded, Doughnut, DoughnutExploded, etc. do not have an axis.
Aspose.Cells provides Chart.HasAxis(AxisType axisType, bool isPrimary) method to determine if the chart has a particular axis or not.
The following sample code demonstrates the use of Chart.HasAxis(AxisType axisType, bool isPrimary) to determine if the sample chart has Primary and Secondary Category and Value Axis.
C# code to determine which axis exists in the chart
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook object | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access the chart | |
Chart chart = worksheet.Charts[0]; | |
//Determine which axis exists in chart | |
bool ret = chart.HasAxis(AxisType.Category, true); | |
Console.WriteLine("Has Primary Category Axis: " + ret); | |
ret = chart.HasAxis(AxisType.Category, false); | |
Console.WriteLine("Has Secondary Category Axis: " + ret); | |
ret = chart.HasAxis(AxisType.Value, true); | |
Console.WriteLine("Has Primary Value Axis: " + ret); | |
ret = chart.HasAxis(AxisType.Value, false); | |
Console.WriteLine("Has Secondary Value Axis: " + ret); |
Console output generated by the sample code
The console output of the code has been shown below which displays true for Primary Category and Value Axis and false for Secondary Category and Value Axis.
Has Primary Category Axis: True
Has Secondary Category Axis: False
Has Primary Value Axis: True
Has Secondary Value Axis: False