ウォーターフォールチャートの作成方法
Contents
[
Hide
]
ウォーターフォールチャートは、通常、出発位置が増加または減少する方法を示すために使用される特別なタイプのチャートです。Microsoft Excelには、カラム、折れ線、円、棒、レーダーなどの事前定義済みのチャートタイプが多数ありますが、ウォーターフォールチャートは基本的なグラフを超えたものであり、既存のチャートタイプを使用して少しのカスタマイズまたはより多くのカスタマイズで作成できます。
Aspose.Cells for Python via .NET APIは、ラインチャートを利用してウォーターフォールチャートを作成できます。また、チャートの外観をカスタマイズし、Series.up_barsとSeries.down_barsのプロパティを設定することでウォーターフォールの形状に調整可能です。
以下のコードスニペットは、Aspose.Cells for Python via .NET APIを使ってゼロからウォーターフォールチャートを作成する例を示しています。
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, FormattingType | |
from aspose.pydrawing import Color | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create an instance of Workbook | |
workbook = Workbook() | |
# Retrieve the first Worksheet in Workbook | |
worksheet = workbook.worksheets[0] | |
# Retrieve the Cells of the first Worksheet | |
cells = worksheet.cells | |
# Input some data which chart will use as source | |
cells.get("A1").put_value("Previous Year") | |
cells.get("A2").put_value("January") | |
cells.get("A3").put_value("March") | |
cells.get("A4").put_value("August") | |
cells.get("A5").put_value("October") | |
cells.get("A6").put_value("Current Year") | |
cells.get("B1").put_value(8.5) | |
cells.get("B2").put_value(1.5) | |
cells.get("B3").put_value(7.5) | |
cells.get("B4").put_value(7.5) | |
cells.get("B5").put_value(8.5) | |
cells.get("B6").put_value(3.5) | |
cells.get("C1").put_value(1.5) | |
cells.get("C2").put_value(4.5) | |
cells.get("C3").put_value(3.5) | |
cells.get("C4").put_value(9.5) | |
cells.get("C5").put_value(7.5) | |
cells.get("C6").put_value(9.5) | |
# Add a Chart of type Line in same worksheet as of data | |
idx = worksheet.charts.add(ChartType.LINE, 4, 4, 25, 13) | |
# Retrieve the Chart object | |
chart = worksheet.charts[idx] | |
# Add Series | |
chart.n_series.add("$B$1:$C$6", True) | |
# Add Category Data | |
chart.n_series.category_data = "$A$1:$A$6" | |
# Series has Up Down Bars | |
chart.n_series[0].has_up_down_bars = True | |
# Set the colors of Up and Down Bars | |
chart.n_series[0].up_bars.area.foreground_color = Color.green | |
chart.n_series[0].down_bars.area.foreground_color = Color.red | |
# Make both Series Lines invisible | |
chart.n_series[0].border.is_visible = False | |
chart.n_series[1].border.is_visible = False | |
# Set the Plot Area Formatting Automatic | |
chart.plot_area.area.formatting = FormattingType.AUTOMATIC | |
# Delete the Legend | |
chart.legend.legend_entries[0].is_deleted = True | |
chart.legend.legend_entries[1].is_deleted = True | |
# Save the workbook | |
workbook.save(dataDir + "output_out.xlsx") |