[]
        
(Showing Draft Content)

箱线图

箱线图是统计图表,通过四分位数、均值和异常值显示数值数据的分布。顾名思义,这些值用方框和触须表示,其中方框表示四分位数的范围(下四分位数、上四分位数和中位数),而触须表示上四分位数和下四分位数之外的可变性。胡须之外的任何一点都被认为是异常值。这些图表对于比较多个组或数据集之间的分布非常有用。例如,您可以轻松地显示两个城市的月温度变化。


用例代码

请参阅以下代码以添加箱线图:

private static void BoxWhiskerChart() {
    // Initialize workbook
    Workbook workbook = new Workbook();
    // Fetch default worksheet
    IWorksheet worksheet = workbook.getWorksheets().get(0);

    // Prepare data for chart
    worksheet.getRange("A1:D16").setValue(new Object[][] { 
        { "Course", "SchoolA", "SchoolB", "SchoolC" },
        { "English", 78, 72, 45 }, 
        { "Physics", 61, 55, 65 }, 
        { "English", 63, 50, 65 }, 
        { "Math", 62, 73, 83 },
        { "English", 46, 64, 75 }, 
        { "English", 58, 56, 67 }, 
        { "Math", 60, 51, 67 }, 
        { "Math", 62, 53, 66 },
        { "English", 63, 54, 64 }, 
        { "English", 90, 52, 67 }, 
        { "Physics", 70, 82, 64 },
        { "English", 60, 56, 67 }, 
        { "Math", 73, 56, 75 }, 
        { "Math", 63, 58, 74 }, 
        { "English", 73, 84, 45 } });
    worksheet.getRange("A:D").getColumns().autoFit();
    // Add BoxWhisker chart
    IShape boxWhiskerChartshape = worksheet.getShapes().addChart(ChartType.BoxWhisker, 300, 20, 300, 200);
    boxWhiskerChartshape.getChart().getSeriesCollection().add(worksheet.getRange("A1:D16"));

    // Configure Chart Title
    boxWhiskerChartshape.getChart().getChartTitle().setText("Box & Whisker Chart");

    // Config value axis's scale
    IAxis value_axis = boxWhiskerChartshape.getChart().getAxes().item(AxisType.Value, AxisGroup.Primary);
    value_axis.setMinimumScale(40);
    value_axis.setMaximumScale(70);

    // Configure the display of box&whisker plot
    ISeries series = boxWhiskerChartshape.getChart().getSeriesCollection().get(0);
    series.setShowInnerPoints(true);
    series.setShowOutlierPoints(false);
    series.setShowMeanMarkers(false);
    series.setShowMeanLine(true);
    series.setQuartileCalculationInclusiveMedian(true);

    // Saving workbook to Xlsx
    workbook.save("28-BoxWhiskerChart.xlsx", SaveFileFormat.Xlsx);