Come creare un grafico TreeMap

Possibili Scenari di Utilizzo

Un grafico a mappa a riquadri fornisce una visualizzazione gerarchica dei tuoi dati e rende facile individuare modelli, ad esempio quali articoli sono i più venduti in un negozio. I rami dell’albero sono rappresentati da rettangoli e ogni sotto-ramo è mostrato come un rettangolo più piccolo. Il grafico a mappa a riquadri visualizza le categorie per colore e prossimità e può facilmente mostrare molti dati che sarebbero difficili da visualizzare con altri tipi di grafico.

todo:image_alt_text

Grafico TreeMap

Dopo aver eseguito il codice qui sotto, vedrai il grafico TreeMap come mostrato di seguito.

todo:image_alt_text

Codice di Esempio

Il seguente codice di esempio carica il file Excel di esempio e genera il file Excel di output.

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