> Markdown version of [Box Plot](https://vaadin.com/docs/next/components/charts/charttypes/box-plot). Section index: [llms.txt](https://vaadin.com/docs/next/components/llms.txt)

# <a id="charts.charttypes.boxplot"></a>Box Plot Charts

Box plot charts display the distribution of statistical variables. A data point has a median, represented with a horizontal line, upper and lower quartiles, represented by a box, and a low and high value, represented with T-shaped "whiskers". The exact semantics of the box symbols are up to you.

Box plot chart is related to the error bar chart described in [Error Bars](https://vaadin.com/docs/next/components/charts/charttypes/error-bars.md#charts.charttypes.errorbar), sharing the box and whisker elements.

[Image: charts boxplot]

Box Plot Chart

The chart type for box plot charts is `ChartType.BOXPLOT`. You normally have only one data series, so it’s meaningful to disable the legend.

```java
Chart chart = new Chart(ChartType.BOXPLOT);

// Modify the default configuration a bit
Configuration conf = chart.getConfiguration();
conf.setTitle("Orienteering Split Times");
conf.getLegend().setEnabled(false);
```

## <a id="charts.charttypes.boxplot.plotoptions"></a>Plot Options

The plot options for box plots have type `PlotOptionsBoxPlot`, which extends the more generic `PlotOptionsErrorBar`.

For example:

```java
// Set median line color and thickness
PlotOptionsBoxplot plotOptions = new PlotOptionsBoxplot();
plotOptions.setWhiskerLength("80%");
conf.setPlotOptions(plotOptions);
```

## <a id="charts.charttypes.boxplot.datamodel"></a>Data Model

As the data points in box plots have five different values instead of the usual one, they require you to use a special `BoxPlotItem`. You can give the different values with the setters, or all at once in the constructor.

```java
// Orienteering control point times for runners
double data[][] = orienteeringdata();

DataSeries series = new DataSeries();
for (double cpointtimes[]: data) {
    StatAnalysis analysis = new StatAnalysis(cpointtimes);
    series.add(new BoxPlotItem(analysis.low(),
                               analysis.firstQuartile(),
                               analysis.median(),
                               analysis.thirdQuartile(),
                               analysis.high()));
}
conf.setSeries(series);
```

## <a id="box-plot-example"></a>Box Plot Example

**Flow** — `ChartTypeBoxPlot.java`

```java
Chart chart = new Chart(ChartType.BOXPLOT);

chart.getConfiguration().setTitle("Box Plot Example");

Legend legend = new Legend();
legend.setEnabled(true);
chart.getConfiguration().setLegend(legend);

XAxis xaxis = chart.getConfiguration().getxAxis();
xaxis.setTitle("Experiment No.");
xaxis.setCategories("1", "2", "3", "4", "5");

YAxis yAxis = chart.getConfiguration().getyAxis();
yAxis.setTitle("Observations");

PlotLine plotLine = new PlotLine();
plotLine.setValue(932);
plotLine.setZIndex(0);
Label label = new Label("Theoretical mean: 932");
label.setAlign(HorizontalAlign.CENTER);
plotLine.setLabel(label);
yAxis.setPlotLines(plotLine);

final DataSeries observations = new DataSeries();
observations.setName("Observations");

// Add PlotBoxItems contain all fields relevant for plot box chart
observations.add(new BoxPlotItem(760, 801, 848, 895, 965));

// Example with no arg constructor
BoxPlotItem plotBoxItem = new BoxPlotItem();
plotBoxItem.setLow(733);
plotBoxItem.setLowerQuartile(853);
plotBoxItem.setMedian(939);
plotBoxItem.setUpperQuartile(980);
plotBoxItem.setHigh(1080);
observations.add(plotBoxItem);

observations.add(new BoxPlotItem(714, 762, 817, 870, 918));
observations.add(new BoxPlotItem(724, 802, 806, 871, 950));
observations.add(new BoxPlotItem(834, 836, 864, 882, 910));
PlotOptionsBoxplot plotOptions = new PlotOptionsBoxplot();
SeriesTooltip observationsTooltip = new SeriesTooltip();
observationsTooltip
        .setHeaderFormat("<em>Experiment No {point.key}</em><br/>");
plotOptions.setTooltip(observationsTooltip);
observations.setPlotOptions(plotOptions);
chart.getConfiguration().addSeries(observations);

final DataSeries outlier = new DataSeries();
outlier.setName("Outlier");

outlier.add(new DataSeriesItem(0, 644));
outlier.add(new DataSeriesItem(4, 718));
outlier.add(new DataSeriesItem(4, 951));
outlier.add(new DataSeriesItem(4, 969));

PlotOptionsScatter outlierOptions = new PlotOptionsScatter();
SeriesTooltip outlierTooltip = new SeriesTooltip();
outlierTooltip.setPointFormat("Observation: {point.y}");
outlierOptions.setTooltip(outlierTooltip);
outlier.setPlotOptions(outlierOptions);

chart.getConfiguration().addSeries(outlier);
```
