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.

// Create an instance of Workbook
Workbook workbook = new Workbook("treemap.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Add a Treemap chart
int pieIdx = worksheet.getCharts().add(ChartType.TREEMAP, 5, 6, 20, 12);
// Retrieve the Chart object
Chart chart = worksheet.getCharts().get(pieIdx);
// Set the legend can be showed
chart.setShowLegend(true);
// Set the chart title name
chart.getTitle().setText("TreeMap Chart");
// Add series data range(D2:D13,actually)
chart.getNSeries().add("D2:F13", true);
// Set category data(A2:A13 is incorrect )
chart.getNSeries().setCategoryData("A2:C13");
// Show the DataLabels with category names
chart.getNSeries().get(0).getDataLabels().setShowCategoryName(true);
// Fill the PlotArea area with nothing
chart.getPlotArea().getArea().getFillFormat().setFillType(FillType.NONE);
// Save the Excel file
workbook.save("out.xlsx");