确定图表中存在哪个轴
Contents
[
Hide
]
有时,用户需要知道图表中是否存在特定轴。例如,他想知道图表中是否存在次要值轴。一些图表,如 Pie、PieExploded、PiePie、PieBar、Pie3D、Pie3DExploded、Doughnut、DoughnutExploded 等没有轴。
Aspose.Cells提供Chart.HasAxis(AxisType axisType, bool isPrimary)确定图表是否具有特定轴的方法。
下面的示例代码演示了使用Chart.HasAxis(AxisType axisType, bool isPrimary)以确定示例图表是否具有主要和次要类别以及值轴。
C# 判断图表中存在哪个轴的代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
示例代码生成的控制台输出
代码的控制台输出如下所示,其中对主要类别和价值轴显示 true,对次要类别和价值轴显示 false。
Has Primary Category Axis: True
Has Secondary Category Axis: False
Has Primary Value Axis: True
Has Secondary Value Axis: False