[]
        
(Showing Draft Content)

组合图

组合图是一个绘图区域中两种或多种图表类型的组合。例如,一个单一绘图中的条形图和折线图。组合图最好用于比较彼此相关的不同数据集,如实际值和目标值、总收入和利润、温度和降水量等。请注意,这些图表可能需要多个轴来满足不同的尺度。

图表类型

图表快照

用例

组合图

Combo_Chart_thumb

组合图

组合图可用于解释和理解完全不相关的不同类型的数据(例如:价格和数量),或在次轴上绘制一个或多个数据系列。

用例代码

请参阅以下示例代码以添加组合图:

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