Comment créer un diagramme en cascade

Contents
[ ]

Les API Aspose.Cells pour Python via .NET permettent de créer un graphique en cascade à l’aide d’un graphique linéaire. L’API permet également de personnaliser l’apparence du graphique pour lui donner la forme d’une cascade en configurant les propriétés Series.up_bars et Series.down_bars.

Le code ci-dessous démontre l’utilisation de l’API Aspose.Cells pour Python via .NET pour créer un graphique en cascade from scratch.

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")