Excelチャートのデータラベルを管理する
Contents
[
Hide
]
データラベルはチャートの重要な部分です。
各シリーズの値、パーセンテージなどを簡単に把握できます。
データラベルオプション
Aspose.Cells for Python via .NET は、DataLabels オブジェクトを使用してチャートのデータラベルを実行時に管理でき、簡単に移動、更新、およびフォーマットできます。
||
データラベルの管理
Aspose.Cells for Python via .NET の DataLabels でチャートのデータラベルを管理するのは簡単です。
次のコードスニペットは、データラベルの管理方法を示しています。
This file contains hidden or 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
from aspose.cells import Workbook | |
from aspose.cells.charts import ChartType, LabelPositionType | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Adding a new worksheet to the Workbook object | |
sheetIndex = workbook.worksheets.add() | |
# Obtaining the reference of the newly added worksheet by passing its sheet index | |
worksheet = workbook.worksheets[sheetIndex] | |
# Adding sample values to cells | |
worksheet.cells.get("A1").put_value(50) | |
worksheet.cells.get("A2").put_value(100) | |
worksheet.cells.get("A3").put_value(150) | |
worksheet.cells.get("B1").put_value(60) | |
worksheet.cells.get("B2").put_value(32) | |
worksheet.cells.get("B3").put_value(50) | |
# Adding a chart to the worksheet | |
chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
# Accessing the instance of the newly added chart | |
chart = worksheet.charts[chartIndex] | |
# Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
chart.n_series.add("A1:B3", True) | |
# Show value labels | |
chart.n_series[0].data_labels.show_value = True | |
# Show series name labels | |
chart.n_series[1].data_labels.show_series_name = True | |
# Move labels to center | |
chart.n_series[1].data_labels.position = LabelPositionType.CENTER | |
# Save the file | |
workbook.save("chart_datalabels.xlsx") |