Box and whisker

24 Mar 202324 minutes to read

To render a box and whisker chart, use seriestype as BoxAndWhisker. The field y requires n number of data or it should contain minimum of five values to plot a segment.

<ejs-chart id="container">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue"
                      name="Department" type="@Syncfusion.EJ2.Charts.ChartSeriesType.BoxAndWhisker">
                      <e-series-marker visible="true" height="10" width="10"></e-series-marker>
                      </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            Double[] y1 = { 22, 22, 23, 25, 25, 25, 26, 27, 27, 28, 28, 29, 30, 32, 34, 32, 34, 36, 35, 38 };
            Double[] y2 = { 22, 33, 23, 25, 26, 28, 29, 30, 34, 33, 32, 31, 50 };
            Double[] y3 = { 22, 24, 25, 30, 32, 34, 36, 38, 39, 41, 35, 36, 40, 56 };
            Double[] y4 = { 26, 27, 28, 30, 32, 34, 35, 37, 35, 37, 45 };
            Double[] y5 = { 26, 27, 29, 32, 34, 35, 36, 37, 38, 39, 41, 43, 58 };
            Double[] y6 = { 27, 26, 28, 29, 29, 29, 32, 35, 32, 38, 53 };
            Double[] y7 = { 21, 23, 24, 25, 26, 27, 28, 30, 34, 36, 38 };
            Double[] y8 = { 26, 28, 29, 30, 32, 33, 35, 36, 52 };
            Double[] y9 = { 28, 29, 30, 31, 32, 34, 35, 36 };

            List<BoxAndWhiskerChartData> chartData = new List<BoxAndWhiskerChartData>
            {
                new BoxAndWhiskerChartData { xValue = "Development", yValue = y1 },
                new BoxAndWhiskerChartData { xValue = "Testing", yValue = y2},
                new BoxAndWhiskerChartData { xValue = "HR", yValue = y3 },
                new BoxAndWhiskerChartData { xValue = "Finance", yValue = y4 },
                new BoxAndWhiskerChartData { xValue = "R&D", yValue = y5 },
                new BoxAndWhiskerChartData { xValue = "Sales", yValue = y6 },
                new BoxAndWhiskerChartData { xValue = "Inventory", yValue = y7 },
                new BoxAndWhiskerChartData { xValue = "Graphics", yValue = y8 },
                new BoxAndWhiskerChartData { xValue = "Training", yValue = y9 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class BoxAndWhiskerChartData
        {
            public string xValue;
            public double[] yValue;
        }

Customization of Box and Whisker series

boxPlotMode

You can change the rendering mode of the Box and Whisker series using the boxPlotMode property. The default boxPlotMode is exclusive. The other boxPlotMode available are inclusive and normal.

To render a box and whisker chart, use seriestype as BoxAndWhisker. The field y requires n number of data or it should contain minimum of five values to plot a segment.

<ejs-chart id="container">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue"
                      name="Department" type="@Syncfusion.EJ2.Charts.ChartSeriesType.BoxAndWhisker"
                      boxPlotMode="Normal">
                <e-series-marker visible="true" height="10" width="10"></e-series-marker>
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            Double[] y1 = { 22, 22, 23, 25, 25, 25, 26, 27, 27, 28, 28, 29, 30, 32, 34, 32, 34, 36, 35, 38 };
            Double[] y2 = { 22, 33, 23, 25, 26, 28, 29, 30, 34, 33, 32, 31, 50 };
            Double[] y3 = { 22, 24, 25, 30, 32, 34, 36, 38, 39, 41, 35, 36, 40, 56 };
            Double[] y4 = { 26, 27, 28, 30, 32, 34, 35, 37, 35, 37, 45 };
            Double[] y5 = { 26, 27, 29, 32, 34, 35, 36, 37, 38, 39, 41, 43, 58 };
            Double[] y6 = { 27, 26, 28, 29, 29, 29, 32, 35, 32, 38, 53 };
            Double[] y7 = { 21, 23, 24, 25, 26, 27, 28, 30, 34, 36, 38 };
            Double[] y8 = { 26, 28, 29, 30, 32, 33, 35, 36, 52 };
            Double[] y9 = { 28, 29, 30, 31, 32, 34, 35, 36 };

            List<BoxAndWhiskerChartData> chartData = new List<BoxAndWhiskerChartData>
            {
                new BoxAndWhiskerChartData { xValue = "Development", yValue = y1 },
                new BoxAndWhiskerChartData { xValue = "Testing", yValue = y2},
                new BoxAndWhiskerChartData { xValue = "HR", yValue = y3 },
                new BoxAndWhiskerChartData { xValue = "Finance", yValue = y4 },
                new BoxAndWhiskerChartData { xValue = "R&D", yValue = y5 },
                new BoxAndWhiskerChartData { xValue = "Sales", yValue = y6 },
                new BoxAndWhiskerChartData { xValue = "Inventory", yValue = y7 },
                new BoxAndWhiskerChartData { xValue = "Graphics", yValue = y8 },
                new BoxAndWhiskerChartData { xValue = "Training", yValue = y9 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class BoxAndWhiskerChartData
        {
            public string xValue;
            public double[] yValue;
        }

showMean

In Box and Whisker series showMean property is used to show the box and whisker average value. The default value of showMean is false.

<ejs-chart id="container">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue"
                      name="Department" type="@Syncfusion.EJ2.Charts.ChartSeriesType.BoxAndWhisker"
                      showMean="false">
                <e-series-marker visible="true" height="10" width="10"></e-series-marker>
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            Double[] y1 = { 22, 22, 23, 25, 25, 25, 26, 27, 27, 28, 28, 29, 30, 32, 34, 32, 34, 36, 35, 38 };
            Double[] y2 = { 22, 33, 23, 25, 26, 28, 29, 30, 34, 33, 32, 31, 50 };
            Double[] y3 = { 22, 24, 25, 30, 32, 34, 36, 38, 39, 41, 35, 36, 40, 56 };
            Double[] y4 = { 26, 27, 28, 30, 32, 34, 35, 37, 35, 37, 45 };
            Double[] y5 = { 26, 27, 29, 32, 34, 35, 36, 37, 38, 39, 41, 43, 58 };
            Double[] y6 = { 27, 26, 28, 29, 29, 29, 32, 35, 32, 38, 53 };
            Double[] y7 = { 21, 23, 24, 25, 26, 27, 28, 30, 34, 36, 38 };
            Double[] y8 = { 26, 28, 29, 30, 32, 33, 35, 36, 52 };
            Double[] y9 = { 28, 29, 30, 31, 32, 34, 35, 36 };

            List<BoxAndWhiskerChartData> chartData = new List<BoxAndWhiskerChartData>
            {
                new BoxAndWhiskerChartData { xValue = "Development", yValue = y1 },
                new BoxAndWhiskerChartData { xValue = "Testing", yValue = y2},
                new BoxAndWhiskerChartData { xValue = "HR", yValue = y3 },
                new BoxAndWhiskerChartData { xValue = "Finance", yValue = y4 },
                new BoxAndWhiskerChartData { xValue = "R&D", yValue = y5 },
                new BoxAndWhiskerChartData { xValue = "Sales", yValue = y6 },
                new BoxAndWhiskerChartData { xValue = "Inventory", yValue = y7 },
                new BoxAndWhiskerChartData { xValue = "Graphics", yValue = y8 },
                new BoxAndWhiskerChartData { xValue = "Training", yValue = y9 },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class BoxAndWhiskerChartData
        {
            public string xValue;
            public double[] yValue;
        }

Waterfall Chart

Waterfall chart helps to understand the cumulative effect of the sequentially introduced positive and negative values. To render a Waterfall series, use series type as Waterfall. intermediateSumIndexes property of waterfall is used to represent inbetween the sum values and sumIndexes is used to represent the cumulative sum values.

@{
    var index = new int[]{4};
    var sumindex = new int[]{8};
}
<ejs-chart id="container">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue"
                      name="Department" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Waterfall"
                      intermediateSumIndexes="index" sumIndexes="sumindex">
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<WaterfallChartData> chartData = new List<WaterfallChartData>
            {
                new WaterfallChartData { xValue = "Income", yValue = 4711 },
                new WaterfallChartData { xValue = "Sales", yValue = -1015 },
                new WaterfallChartData { xValue = "Development", yValue = -688 },
                new WaterfallChartData { xValue = "Revenue", yValue = 1030 },
                new WaterfallChartData { xValue = "Balance" },
                new WaterfallChartData { xValue = "Expense", yValue = -361 },
                new WaterfallChartData { xValue = "Tax", yValue = -695 },
                new WaterfallChartData { xValue = "Net Profit" },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class WaterfallChartData
        {
            public string xValue;
            public double yValue;
        }

Customization of Waterfall Series

The negative changes of waterfall charts is represented by using negativeFillColor and the summary changes are represented by using summaryFillColor properties.

By default, the negativeFillColor as ‘#E94649’ and the summaryFillColor as ‘#4E81BC’.

@{
    var index = new int[]{4};
    var sumindex = new int[]{8};
}
<ejs-chart id="container">
        <e-chart-primaryxaxis valueType="Category"></e-chart-primaryxaxis>
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="xValue" yName="yValue"
                      name="Department" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Waterfall"
                      intermediateSumIndexes="index" sumIndexes="sumindex"
                      summaryFillColor="#e56590"
                      negativeFillColor="#f8b883">
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<WaterfallChartData> chartData = new List<WaterfallChartData>
            {
                new WaterfallChartData { xValue = "Income", yValue = 4711 },
                new WaterfallChartData { xValue = "Sales", yValue = -1015 },
                new WaterfallChartData { xValue = "Development", yValue = -688 },
                new WaterfallChartData { xValue = "Revenue", yValue = 1030 },
                new WaterfallChartData { xValue = "Balance" },
                new WaterfallChartData { xValue = "Expense", yValue = -361 },
                new WaterfallChartData { xValue = "Tax", yValue = -695 },
                new WaterfallChartData { xValue = "Net Profit" },
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class WaterfallChartData
        {
            public string xValue;
            public double yValue;
        }

Error Bar Chart

Error bars are graphical representations of the variability of data and used on graphs to indicate the error or uncertainty in a reported measurement. To render the error bar for the series, set visible as true in error bar object.

<ejs-chart id="container" width="60%">
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x"  yName="y"
             type="@Syncfusion.EJ2.Charts.ChartSeriesType.Line">
                <e-series-errorbar visible="true"></e-series-errorbar>
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<ErrorBarData> chartData = new List<ErrorBarData>
            {
               new ErrorBarData{ x= 2005, y= 28 },
               new ErrorBarData{ x= 2006, y= 25 },
               new ErrorBarData{ x= 2007, y= 26 }, 
               new ErrorBarData{ x= 2008, y= 27 },
               new ErrorBarData{ x= 2009, y= 32 },
               new ErrorBarData{ x= 2010, y= 35 }, 
               new ErrorBarData{ x= 2011, y= 30 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ErrorBarData
         {
            public double x;
            public double y;
        }

Changing Error Bar Type

To change the error bar rendering type using type option of error bar. To change the error bar line length you can use verticalError property.

<ejs-chart id="container" load="window.onload" width="60%">
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x"  yName="y"
             type="@Syncfusion.EJ2.Charts.ChartSeriesType.Line">
                <e-series-errorbar visible="true" type="Percentage" verticalError="4"></e-series-errorbar>
            </e-series>
        </e-series-collection>
</ejs-chart>
public ActionResult Index()
        {
            List<ErrorBarData> chartData = new List<ErrorBarData>
            {
               new ErrorBarData{ x= 2005, y= 28 },
               new ErrorBarData{ x= 2006, y= 25 },
               new ErrorBarData{ x= 2007, y= 26 }, 
               new ErrorBarData{ x= 2008, y= 27 },
               new ErrorBarData{ x= 2009, y= 32 },
               new ErrorBarData{ x= 2010, y= 35 }, 
               new ErrorBarData{ x= 2011, y= 30 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ErrorBarData
         {
            public double x;
            public double y;
        }

Customizing Error Bar Type

To customize the error bar type, set error bar type as Custom and then change the horizontal/vertical positive and negative error of error bar.

<ejs-chart id="container" load="window.onload" width="60%">
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x"  yName="y"
             type="@Syncfusion.EJ2.Charts.ChartSeriesType.Line">
                <e-series-errorbar visible="true" type="Custom" mode="Both" 
                 verticalPositiveError="3" horizontalPositiveError="2"
                 verticalNegativeError="3" horizontalNegativeError="2"></e-series-errorbar>
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<ErrorBarData> chartData = new List<ErrorBarData>
            {
               new ErrorBarData{ x= 2005, y= 28 },
               new ErrorBarData{ x= 2006, y= 25 },
               new ErrorBarData{ x= 2007, y= 26 }, 
               new ErrorBarData{ x= 2008, y= 27 },
               new ErrorBarData{ x= 2009, y= 32 },
               new ErrorBarData{ x= 2010, y= 35 }, 
               new ErrorBarData{ x= 2011, y= 30 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ErrorBarData
         {
            public double x;
            public double y;
        }

Changing Error Bar Mode

Error bar mode is used to define whether the error bar line has to be drawn horizontally, vertically or in both side. To change the error bar mode use mode option.

<ejs-chart id="container" load="window.onload" width="60%">
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x"  yName="y"
             type="@Syncfusion.EJ2.Charts.ChartSeriesType.Line">
                <e-series-errorbar visible="true" mode="Horizontal"></e-series-errorbar>
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<ErrorBarData> chartData = new List<ErrorBarData>
            {
               new ErrorBarData{ x= 2005, y= 28 },
               new ErrorBarData{ x= 2006, y= 25 },
               new ErrorBarData{ x= 2007, y= 26 }, 
               new ErrorBarData{ x= 2008, y= 27 },
               new ErrorBarData{ x= 2009, y= 32 },
               new ErrorBarData{ x= 2010, y= 35 }, 
               new ErrorBarData{ x= 2011, y= 30 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ErrorBarData
         {
            public double x;
            public double y;
        }

Changing Error Bar Direction

To change the error bar direction to plus, minus or both side using direction option.

<ejs-chart id="container" load="window.onload" width="60%">
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x"  yName="y"
             type="@Syncfusion.EJ2.Charts.ChartSeriesType.Line">
                <e-series-errorbar visible="true" mode="Vertical" direction="Minus"></e-series-errorbar>
            </e-series>
        </e-series-collection>
    </ejs-chart>
public ActionResult Index()
        {
            List<ErrorBarData> chartData = new List<ErrorBarData>
            {
               new ErrorBarData{ x= 2005, y= 28 },
               new ErrorBarData{ x= 2006, y= 25 },
               new ErrorBarData{ x= 2007, y= 26 }, 
               new ErrorBarData{ x= 2008, y= 27 },
               new ErrorBarData{ x= 2009, y= 32 },
               new ErrorBarData{ x= 2010, y= 35 }, 
               new ErrorBarData{ x= 2011, y= 30 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ErrorBarData
         {
            public double x;
            public double y;
        }

Customizing Error Bar Cap

To customize the error bar cap length, width and fill color, you can use errorBarCap option.

<ejs-chart id="container" load="window.onload" width="60%">
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x"  yName="y"
             type="@Syncfusion.EJ2.Charts.ChartSeriesType.Line">
                <e-series-errorbar visible="true">
                    <e-errorbarcap length="10" width="10" color="#0000ff"></e-errorbarcap>
                </e-series-errorbar>
            </e-series>
        </e-series-collection>
</ejs-chart>
public ActionResult Index()
        {
            List<ErrorBarData> chartData = new List<ErrorBarData>
            {
               new ErrorBarData{ x= 2005, y= 28 },
               new ErrorBarData{ x= 2006, y= 25 },
               new ErrorBarData{ x= 2007, y= 26 }, 
               new ErrorBarData{ x= 2008, y= 27 },
               new ErrorBarData{ x= 2009, y= 32 },
               new ErrorBarData{ x= 2010, y= 35 }, 
               new ErrorBarData{ x= 2011, y= 30 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ErrorBarData
         {
            public double x;
            public double y;
        }

Customizing Error Bar Color

To customize the error bar color for individual errors, use the errorBarColorMapping property. You can also customize the vertical error, horizontal error, horizontal negative and positive error and vertical negative and positive error for an individual point using verticalError, horizontalError, horizontalNegativeError, horizontalPositiveError, verticalNegativeError and verticalPositiveError properties.

<ejs-chart id="container" load="window.onload" width="60%">
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x"  yName="y"
             type="@Syncfusion.EJ2.Charts.ChartSeriesType.Line">
             <e-series-errorbar visible="true" verticalError="Error" errorBarColorMapping="color">
            </e-series>
        </e-series-collection>
</ejs-chart>
public ActionResult Index()
        {
            List<ErrorBarData> chartData = new List<ErrorBarData>
            {
               new ErrorBarData{ x= 2005, y= 28, color= 'red', error= 4 },
               new ErrorBarData{ x= 2006, y= 25, color= 'blue', error= 3 },
               new ErrorBarData{ x= 2007, y= 26, color= 'green', error= 1 }, 
               new ErrorBarData{ x= 2008, y= 27, color= 'orange', error= 5 },
               new ErrorBarData{ x= 2009, y= 32, color= 'yellow', error= 7 },
               new ErrorBarData{ x= 2010, y= 35, color= 'grey', error= 2 }, 
               new ErrorBarData{ x= 2011, y= 30, color= 'brown', error= 6 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class ErrorBarData
         {
            public double x;
            public double y;
            public string color;
            public double error;
        }

Vertical Chart

In EJ2 chart, you can draw a chart in vertical manner by changing orientation of the axis. All series types support this feature. You can use isTransposed property in chart to render a chart in vertical manner.

<ejs-chart id="container" isTransposed="true" width="60%">
        <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="x"  yName="y"
             type="@Syncfusion.EJ2.Charts.ChartSeriesType.Spline"></e-series>
        </e-series-collection>
</ejs-chart>
public ActionResult Index()
        {
            List<VerticalData> chartData = new List<VerticalData>
            {
               new VerticalData{ x= 2005, y= 28 },
               new VerticalData{ x= 2006, y= 25 },
               new VerticalData{ x= 2007, y= 26 }, 
               new VerticalData{ x= 2008, y= 27 },
               new VerticalData{ x= 2009, y= 32 },
               new VerticalData{ x= 2010, y= 35 }, 
               new VerticalData{ x= 2011, y= 30 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }
        public class VerticalData
        {
            public double x;
            public double y;
        }

Pareto chart

Pareto charts are used to find the cumulative values of data in different categories. It is a combination of Column and Line series. The initial values are represented by column chart and the cumulative values are represented by Line chart. To render a pareto chart, use series type as Pareto.

<ejs-chart id="container" enableAnimation="true">
    <e-chart-primaryyaxis title="Frequency" minimum="0" maximum="150" interval="30" valueType="Category">
    </e-chart-primaryyaxis>
    <e-chart-primaryxaxis title="Defect" valueType="Category">
    </e-chart-primaryxaxis>
    <e-series-collection>
        <e-series dataSource="ViewBag.dataSource" name="Gold" xName="x" yName="y" type="@Syncfusion.EJ2.Charts.ChartSeriesType.Pareto">
            <e-series-marker visible="true" width="10" height="10">
            </e-series-marker>
        </e-series>
    </e-series-collection>
</ejs-chart>
public ActionResult Index()
        {
            List<ColumnChartData> chartData = new List<ColumnChartData>
            {
                new ColumnChartData{ x= "Traffic", y=56  },
                new ColumnChartData{ x="Child care", y=44.8 },
                new ColumnChartData{ x= "Transport", y=27.2 },
                new ColumnChartData{ x= "Weather", y=19.6},
                new ColumnChartData{ x= "Emergency", y=6.6 }
            };
            ViewBag.dataSource = chartData;
            return View();
        }

        public class ColumnChartData
        {
            public string x;
            public double y;
        };

See Also