Skip to main content

Box plot in a table

A box plot shows how a measure is spread: the middle half of the values as a box, the median as a line in the box, and whiskers for the rest. This template draws one in every row of a table.

Box plot drawn in each row of a table
Set up first

Add the function library and import it into your dataset first. See SVG charts in tables.

Add the metric​

Call SVG.Viz.Boxplot from a metric of type text, and wrap it in SVG.Html.Box to fix the size in the cell.

metric box_plot {
label: 'Box Plot'
type: 'text'
definition: @aql
SVG.Html.Box(
300, 50,
SVG.Viz.Boxplot(
products,
products.id,
count(orders.id),
'#22cf13',
null,
300,
50
)
)
;;
}

Parameters​

SVG.Viz.Boxplot​

SVG.Viz.Boxplot takes these parameters in order.

ParameterTypeWhat it is
pAxisModelmodelThe model whose rows the statistics run over, such as products.
pAxisRefdimensionThe dimension that splits the model into the points of the plot, such as products.id.
pMeasureRefnumberThe measure to plot, such as count(orders.id).
pFillColortextBox fill color. null uses the default blue.
pStrokeColortextLine color. null uses #333333.
pWidthnumberWidth of the chart's drawing grid. Sets the proportions, not the display size. null uses 120.
pHeightnumberHeight of the chart's drawing grid. Sets the proportions, not the display size. null uses 48.

SVG.Html.Box​

SVG.Html.Box sets how big the chart looks in the table cell. Without it, the chart stretches to the full width of the cell.

ParameterTypeWhat it is
pWidthnumberDisplay width in pixels.
pHeightnumberDisplay height in pixels.
pContentstextThe chart to show, such as the result of SVG.Viz.Boxplot.

The chart scales to fit this box and keeps its proportions. Use the same width-to-height ratio as the chart's pWidth and pHeight, or the chart leaves empty space around it.

Use it in a table​

Put the metric next to the dimension you want a row for.

explore {
dimensions {
product_name: products.name
}
measures {
box_plot: box_plot
}
}

How to read it​

  • The box runs from the 25th to the 75th percentile.
  • The line in the box is the median.
  • The whiskers reach the lowest and highest values within 1.5 times the box width. They stop at the minimum or maximum if those are closer.
  • Circles beyond the whiskers are outliers.
  • The scale runs from the minimum to the maximum of the row, so each row fills its own width.

Open Markdown
Let us know what you think about this document :)