Cómo crear un gráfico TreeMap

Escenarios de uso posibles

Un gráfico Treemap proporciona una vista jerárquica de sus datos y facilita detectar patrones, como cuáles son los artículos más vendidos de una tienda. Las ramas del árbol están representadas por rectángulos y cada subrama se muestra como un rectángulo más pequeño. El gráfico Treemap muestra categorías por color y proximidad y puede mostrar fácilmente muchos datos que serían difíciles con otros tipos de gráficos.

todo:image_alt_text

Gráfico TreeMap

Después de ejecutar el código a continuación, verá el gráfico TreeMap como se muestra a continuación.

todo:image_alt_text

Código de muestra

El siguiente código de muestra carga el archivo de Excel de muestra y genera el archivo de Excel de salida.

from aspose.cells import Workbook
from aspose.cells.charts import ChartType
from aspose.cells.drawing import FillType
# Create an instance of Workbook
workbook = Workbook("treemap.xlsx")
# Access the first worksheet
worksheet = workbook.worksheets[0]
# Add a Treemap chart
pieIdx = worksheet.charts.add(ChartType.TREEMAP, 5, 6, 20, 12)
# Retrieve the Chart object
chart = worksheet.charts[pieIdx]
# Set the legend can be showed
chart.show_legend = True
# Set the chart title name
chart.title.text = "TreeMap Chart"
# Add series data range(D2:D13,actually)
chart.n_series.add("D2:F13", True)
# Set category data(A2:A13 is incorrect )
chart.n_series.category_data = "A2:C13"
# Show the DataLabels with category names
chart.n_series[0].data_labels.show_category_name = True
# Fill the PlotArea area with nothing
chart.plot_area.area.fill_format.fill_type = FillType.NONE
# Save the Excel file
workbook.save("out.xlsx")