ツリーマップチャートの作成方法

可能な使用シナリオ

ツリーマップチャートは、データを階層ビューで表し、店舗の売れ筋商品などのパターンを簡単に把握できます。ツリーのブランチは長方形で表され、各サブブランチは小さな長方形として表示されます。ツリーマップチャートは、色と近接性でカテゴリを表示し、他のチャートタイプでは難しい大量のデータを簡単に表示できます。

todo:image_alt_text

ツリーマップチャート

以下のコードを実行すると、下記のツリーマップチャートが表示されます。

todo:image_alt_text

サンプルコード

下記のサンプルコードは、サンプルExcelファイルを読み込み、出力Excelファイルを生成します。

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