DEPRECATED: Chart.js Box and Violin Plot
Chart.js module for charting box and violin plots. Works only with Chart.js >= 2.8.0
DEPRECATION Information
Please note that this project has been archived and is no longer being maintained. There is an active fork https://github.com/sgratzl/chartjs-chart-boxplot and we will also contribute our future changes to it.
Install
npm install --save chart.js chartjs-chart-box-and-violin-plot
Usage
see Samples on Github
and CodePen
Chart
four new types: boxplot
, horizontalBoxplot
, violin
, and horizontalViolin
.
Config
tooltipDecimals?: number;
Styling
The boxplot element is called boxandwhiskers
. The basic options are from the rectangle
element. The violin element is called violin
also based on the rectangle
element.
interface IBaseStyling {
backgroundColor: string;
borderColor: string;
medianColor: string;
borderWidth: number;
outlierRadius: number;
outlierColor: string;
lowerColor: string;
itemRadius: number;
itemStyle: 'circle'|'triangle'|'rect'|'rectRounded'|'rectRot'|'cross'|'crossRot'|'star'|'line'|'dash';
itemBackgroundColor: string;
itemBorderColor: string;
hitPadding: number;
outlierHitRadius: number;
}
interface IBoxPlotStyling extends IBaseStyling {
}
interface IViolinStyling extends IBaseStyling {
points: number;
}
In addition, two new scales were created arrayLinear
and arrayLogarithmic
. They were needed to adapt to the required data structure.
Scale Options
Both arrayLinear
and arrayLogarithmic
support the two additional options to their regular counterparts:
interface IArrayLinearScale {
ticks: {
minStats: 'min'|'q1'|'whiskerMin';
maxStats: 'max'|'q3'|'whiskerMax';
coef: number;
quantiles: 7 | 'quantiles' | 'hinges' | 'fivenum' | ((sortedArr: number[]) => {min: number, q1: number, median: number, q3: number, max: number});
};
}
Data structure
Both types support that the data is given as an array of numbers number[]
. The statistics will be automatically computed. In addition, specific summary data structures are supported:
interface IBaseItem {
min: number;
median: number;
max: number;
items?: number[];
}
interface IBoxPlotItem extends IBaseItem {
q1: number;
q3: number;
whiskerMin?: number;
whiskerMax?: number;
outliers?: number[];
}
interface IKDESamplePoint {
v: number;
estimate: number;
}
interface IViolinItem extends IBaseItem {
coords: IKDESamplePoint[];
}
Note: The statistics will be cached within the array. Thus, if you manipulate the array content without creating a new instance the changes won't be reflected in the stats. See also CodePen for a comparison.
Tooltips
In order to simplify the customization of the tooltips, two additional tooltip callback methods are available. Internally the label
callback will call the correspondig callback depending on the type.
arr = {
options: {
tooltips: {
callbacks: {
boxplotLabel: function(item, data, stats, hoveredOutlierIndex) {
return 'Custom tooltip';
},
violinLabel: function(item, data, stats) {
return 'Custom tooltip';
},
}
}
}
}
Building
npm install
npm run build
Angular CLI Usage
Here is an example project based on Angular CLI with Angular 7 dependencies: https://github.com/sluger/ng-chartjs-boxplot
The incomaptibility with Webpack 4, mjs and Angular CLI can be solved by importing the chartjs boxplot library via the .js
build artifact:
import "chartjs-chart-box-and-violin-plot/build/Chart.BoxPlot.js";
This repository is part of the Target Discovery Platform (TDP). For tutorials, API docs, and more information about the build and deployment process, see the documentation page.