BoxWhisker charts are statistical charts that display the distribution of numerical data through quartiles, means and outliers. As the name suggests, these values are represented using boxes and whiskers, where boxes show the range of quartiles (lower quartile, upper quartile and median), while whiskers indicate the variability outside the upper and lower quartiles. Any point outside the whiskers is said to be an outlier. These charts are useful for comparing distributions between many groups or data sets. For instance, you can easily display the variation in monthly temperature of two cities.
Refer to the following code to add Box and Whisker chart:
Java |
Copy Code |
---|---|
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); |