Modo facile per la configurazione del grafico utilizzando il metodo Chart.SetChartDataRange
Contents
[
Hide
]
Aspose.Cells per Python via .NET ora fornisce il metodo Chart.set_chart_data_range() per configurare facilmente i grafici. Usando questo metodo, non sarà più necessario aggiungere i dati delle serie e dell’asse delle categorie separatamente.
Il seguente codice di esempio spiega l’uso del metodo Chart.set_chart_data_range() per configurare facilmente il grafico.
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 FileFormatType, SaveFormat, Workbook | |
from aspose.cells.charts import ChartType | |
# 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 new workbook | |
workbook = Workbook(FileFormatType.XLSX) | |
# Access first worksheet | |
worksheet = workbook.worksheets[0] | |
# Add data for chart | |
# Category Axis Values | |
worksheet.cells.get("A2").put_value("C1") | |
worksheet.cells.get("A3").put_value("C2") | |
worksheet.cells.get("A4").put_value("C3") | |
# First vertical series | |
worksheet.cells.get("B1").put_value("T1") | |
worksheet.cells.get("B2").put_value(6) | |
worksheet.cells.get("B3").put_value(3) | |
worksheet.cells.get("B4").put_value(2) | |
# Second vertical series | |
worksheet.cells.get("C1").put_value("T2") | |
worksheet.cells.get("C2").put_value(7) | |
worksheet.cells.get("C3").put_value(2) | |
worksheet.cells.get("C4").put_value(5) | |
# Third vertical series | |
worksheet.cells.get("D1").put_value("T3") | |
worksheet.cells.get("D2").put_value(8) | |
worksheet.cells.get("D3").put_value(4) | |
worksheet.cells.get("D4").put_value(2) | |
# Create Column chart with easy way | |
idx = worksheet.charts.add(ChartType.COLUMN, 6, 5, 20, 13) | |
ch = worksheet.charts[idx] | |
ch.set_chart_data_range("A1:D4", True) | |
# Save the workbook | |
workbook.save(dataDir + "output_out.xlsx", SaveFormat.XLSX) |