sgratzl / chartjs-chart-boxplot

Chart.js Box Plots and Violin Plot Charts
https://www.sgratzl.com/chartjs-chart-boxplot/
MIT License
101 stars 23 forks source link

Boxplot axis doesn't extend for precomputed outliers #102

Closed Astra3 closed 4 months ago

Astra3 commented 4 months ago

When creating boxplot using precomputed values, the y axis doesn't extend for outliers.

To Reproduce

The following data shows the issue:

const boxplotData = {
  labels: ["outliers not shown"],
  datasets: [
    {
      label: "Dataset 1",
      borderWidth: 1,
      itemRadius: 2,
      itemStyle: "circle",
      itemBackgroundColor: "#000",
      outlierBackgroundColor: "#000",
      data: [
        {
          min: 1,
          q1: 2,
          median: 3,
          q3: 4,
          max: 5,
          // the graph does not extend enough to show these outliers
          outliers: [-5, 11]
        }
      ]
    }
  ]
};

I've created an example on codepen. The outliers are shown if you set the y scale explicitly by uncommenting lines 38 and 39.

Expected behavior

The graph should extend the axis for precomputed outliers when minStats: 'min' and maxStats: 'max' as it already does for non-precomputed values as seen in the first dataset in datastructures example.

Context

sgratzl commented 4 months ago

I'm confused, you define the min and max values of the boxplot, so the minimal and the maximal values. How can an outlier be smaller/larger than that? it would mean that the outlier is smaller than the minimum?

Astra3 commented 4 months ago

You're right, I was trying to create a graph where the whiskers are showing the IQR (i. e. $Q_1 - 1.5 * \text{IQR}$ for the lower whisker) and outliers are showing possible max and min values if they're higher/lower than the IQR whiskers. But I found out I can use whiskerMin to show the lower IQR/min value and then min to show the actual minimal outlier (if it's lower than the computer IQR) instead of using outliers property.