チャートに存在する軸を特定する
Contents
[
Hide
]
場合によっては、特定の軸がチャートに存在するかどうかをユーザーが知る必要があります。たとえば、グラフ内に第 2 値軸が存在するかどうかを知りたいとします。 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