Violin plot
Since 0.1.0-alpha.23Use violins when the shape of each group's values matters, such as a second peak a box plot would hide. They need many values per group. With only a few, the outline shows a shape that isn't really there, so use a box plot.
A violin plot
ChartViolinSeries makes a violin from the Values of the items that share an Argument. Here weekend orders that wait for Monday make a second peak.
Static
Preview
| Carrier | Median | Lower quartile | Upper quartile | Lower whisker | Upper whisker | Values | Outliers |
|---|---|---|---|---|---|---|---|
| Northwind Post | 2.7 | 2.1 | 4 | 1.3 | 5.5 | 220 | 0 |
| Swift Freight | 1.9 | 1.6 | 2.1 | 1.1 | 2.8 | 200 | 3 |
| Coastline Express | 3.65 | 2.98 | 4.33 | 1.9 | 5.8 | 180 | 3 |
Code
@* Days from order to delivery for a month's parcels with three carriers. Two of them don't pick
up at weekends, so orders placed Friday to Sunday wait a day or two longer: a second peak a box
plot would hide inside its box. *@
<Chart Items="_parcels" Argument="p => p.Carrier" Title="Delivery time by carrier, March">
<ChartValueAxis Title="Days from order to delivery" />
<ChartViolinSeries Value="p => p.Days" Name="Delivery time" />
</Chart>
{
private record Parcel(string Carrier, double Days);
// Sample data: each carrier's weekday time, and how much longer a weekend order waits (0: it
// picks up every day).
private readonly Parcel[] _parcels =
[
.. Parcels("Northwind Post", 2.2, 2.0, 220, seed: 1),
.. Parcels("Swift Freight", 1.8, 0, 200, seed: 2),
.. Parcels("Coastline Express", 3.0, 1.6, 180, seed: 3),
];
private static IEnumerable<Parcel> Parcels(string carrier, double median, double weekendWait, int count, int seed)
{
var random = new Random(seed);
return Enumerable.Range(0, count).Select(k =>
{
// Three days in seven are Friday to Sunday.
var weekend = random.Next(7) >= 4;
var normal = Math.Sqrt(-2 * Math.Log(1 - random.NextDouble())) * Math.Cos(2 * Math.PI * random.NextDouble());
var days = median * Math.Exp(0.2 * normal) + (weekend ? weekendWait : 0);
return new Parcel(carrier, Math.Round(days, 1));
}).ToList();
}
}Add this example to a page with the izzy CLI:
izzy add component ChartViolinSeries --at <file>:<line>The density is a Gaussian kernel with Silverman's bandwidth, trimmed to each group's smallest and largest value, so it never reaches a value no item has. Every violin is as wide at its densest.
The box inside marks the quartiles, the median and Tukey's whiskers, as on a box plot. ShowMean adds the mean.
SeriesBy puts a violin per group side by side, and the chart's Orientation="Orientation.Horizontal" lays them across. A violin's chart holds only box plot and violin series.
Details
Inside, a slim box from the first quartile to the third, a line at the median, and a line to Tukey's whiskers; outliers past them are circles. The density is a Gaussian kernel with Silverman's bandwidth (as Plotly's), trimmed to the values' range, and every violin is as wide at its densest. SeriesBy puts a violin per group side by side; the chart's Orientation="Orientation.Horizontal" lays them across. A violin's chart holds only box plot and violin series.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| Each group's density, a Gaussian kernel with Silverman's bandwidth, trimmed to its values | Yes | Yes |
| A slim box, median and whiskers inside, with outliers as circles | Yes | Yes |
| Every violin as wide at its densest, so shapes compare | Yes | Yes |
| Violins split by a group, side by side, upright or across | Yes | Yes |
| Each violin's median and middle half in its tooltip, every number in the table | Yes | Yes |
| A table of the values behind a "Show data" button | Yes | Yes |
| Tooltips on hover and from the keyboard | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Without JavaScript
Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off.
- Tooltips on hover and from the keyboard: waits for the script
Parameters
| Prop | Type | Default |
|---|---|---|
ValueEach item's value, such as d => d.Days: a number, or null to leave the item out. | Expression<Func<TItem, object?>> | Required |
ShowMeanMarks each violin's mean with a diamond, and says it in the tooltip and data table. | bool | false |
AggregateWith ChartDrillLevel<T>s, how each level adds up its items' values: DataAggregate.Sum (the default), DataAggregate.Avg, DataAggregate.Min, DataAggregate.Max or DataAggregate.Count (the items with a value). | DataAggregate | DataAggregate.Sum |
NameThe series' name, in the legend, the data table and each value's description. | string? | computed |
SeriesBySplits the series into one per value of this, such as p => p.Device: each draws only its own items' values, is named by its value, and takes the next color and marker, in the order the values first appear. | Expression<Func<TItem, object?>>? | |
ColorA CSS color, such as var(--ib-color-danger) or #0f766e. | string? | computed |
LabelsWrites each value beside its bar or point. | ChartLabels | ChartLabels.None |
LabelFormatA .NET format string for this series' labels, such as C0. | string? | computed |
LabelTextWhat each label says in place of its value, such as r => r.Region to name each bubble or point. | Expression<Func<TItem, object?>>? | |
LabelOverlapWhat labels do when they'd overlap others: left out at those widths (ChartLabelOverlap.Hide, the default), or shown anyway (ChartLabelOverlap.Show). | ChartLabelOverlap | ChartLabelOverlap.Hide |
TrendDraws a trend through the values: a dashed line in the series' color, named "Revenue trend" (a moving average "Revenue, 7-day average") in the legend, tooltips and data table. | ChartTrend | ChartTrend.None |
TrendOrderA polynomial trend's order, 2 (a parabola) to 6. | int | 2 |
TrendPeriodHow many values a moving average takes in, 2 or more. | int | 3 |
TrendColorThe trend's CSS color, such as var(--ib-color-danger), used as given. | string? | computed |
ValueAxisThe Name of the value axis the series is read off, for a measure in other units on a second axis at the end side, such as "margin". | string? | computed |
HiddenStarts with the series hidden: the chart is drawn as if it weren't there, and it keeps its place in the legend, to show it again, and in the data table. | bool | false |