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:
C# |
Copy Code |
---|---|
public void BoxWhiskerChart() { // Initialize workbook Workbook workbook = new Workbook(); // Fetch default worksheet IWorksheet worksheet = workbook.Worksheets[0]; // Prepare data for chart worksheet.Range["A1:D16"].Value = 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.Range["A:D"].Columns.AutoFit(); //Add BoxWhisker chart IShape boxWhiskerChartshape = worksheet.Shapes.AddChart(ChartType.BoxWhisker, 300, 20, 300, 200); boxWhiskerChartshape.Chart.SeriesCollection.Add(worksheet.Range["A1:D16"]); // Configure Chart Title boxWhiskerChartshape.Chart.ChartTitle.Text = "Box & Whisker Chart"; //Config value axis's scale IAxis value_axis = boxWhiskerChartshape.Chart.Axes.Item(AxisType.Value, AxisGroup.Primary); value_axis.MinimumScale = 40; value_axis.MaximumScale = 70; //Configure the display of box&whisker plot ISeries series = boxWhiskerChartshape.Chart.SeriesCollection[0]; series.ShowInnerPoints = true; series.ShowOutlierPoints = false; series.ShowMeanMarkers = false; series.ShowMeanLine = true; series.QuartileCalculationInclusiveMedian = true; // Saving workbook to Xlsx workbook.Save(@"28-BoxWhiskerChart.xlsx", SaveFileFormat.Xlsx); } |