Easy way for Chart Setup using Chart.SetChartDataRange method
Contents
[
Hide
]
Aspose.Cells for Python via .NET now provides Chart.set_chart_data_range() method to set up chart easily. Using this method, you will now not need to add series and category axis data separately.
The following sample code explains the use Chart.set_chart_data_range() method to set up chart easily.
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) |