Combo chart is a combination of two or more chart types in a single plot area. For instance, a bar and line chart in a single plot. Combination charts are best used to compare the different data sets that are related to each other, such as actual and target values, total revenue and profit, temperature and precipitation etc. Note that these charts may require multiple axes to cater different scales.
Chart Type | Chart Snapshot | Use Case |
---|---|---|
Combo | Combo chart can be used to interpret and understand different type of data that is completely unrelated (for instance: price and volume) or to plot one or more data series on the secondary axis. |
Refer to the following example code to add Combo Chart:
Java |
Copy Code |
---|---|
private static void ComboCharts() { // Initialize workbook Workbook workbook = new Workbook(); // Fetch default worksheet IWorksheet worksheet = workbook.getWorksheets().get(0); // Prepare data for chart worksheet.getRange("A1:C17") .setValue(new Object[][] { { "Mobile Phones", "Laptops", "Tablets" }, { 1350, 120, 75 }, { 1500, 90, 35 }, { 1200, 80, 50 }, { 1300, 80, 80 }, { 1750, 90, 100 }, { 1640, 120, 130 }, { 1700, 120, 95 }, { 1100, 90, 80 }, { 1350, 120, 75 }, { 1500, 90, 35 }, { 1200, 80, 50 }, }); worksheet.getRange("A:C").getColumns().autoFit(); // Add Combination Chart IShape comboChartShape = worksheet.getShapes().addChart(ChartType.Combo, 250, 20, 360, 230); // Adding series to SeriesCollection comboChartShape.getChart().getSeriesCollection().add(worksheet.getRange("A1:C17"), RowCol.Columns); // Configure Chart Title comboChartShape.getChart().getChartTitle().setText("Annual Sales Record-Combination Chart"); ISeries series1 = comboChartShape.getChart().getSeriesCollection().get(0); ISeries series2 = comboChartShape.getChart().getSeriesCollection().get(1); ISeries series3 = comboChartShape.getChart().getSeriesCollection().get(2); // Change series type to make it Combination chart of different ChartTypes series1.setChartType(ChartType.Area); series2.setChartType(ChartType.ColumnStacked); series3.setChartType(ChartType.Line); // Set axis group series2.setAxisGroup(AxisGroup.Secondary); series3.setAxisGroup(AxisGroup.Secondary); // Configure axis scale and unit IAxis value_axis = comboChartShape.getChart().getAxes().item(AxisType.Value); IAxis value_second_axis = comboChartShape.getChart().getAxes().item(AxisType.Value, AxisGroup.Secondary); value_axis.setMaximumScale(1800); value_axis.setMajorUnit(450); value_second_axis.setMaximumScale(300); value_second_axis.setMajorUnit(75); // Saving workbook to Xlsx workbook.save("24-ComboChart.xlsx", SaveFileFormat.Xlsx); |