ecomfe / echarts-stat

Statistics tool for Apache ECharts
593 stars 309 forks source link

Datasets with one value break freedmanDiaconis and scott methods #42

Open hughess opened 2 years ago

hughess commented 2 years ago

Occasionally, I need to show a histogram that contains only one value (the dataset below is an example):

[
{a: 5},
{a: 5},
{a: 5},
{a: 5},
{a: 5},
{a: 5},
{a: 5}
]

This works with the default bin method (square root) and works with sturges, but does not work with freedmanDiaconis or scott. For the two methods where it does not work, I receive an "Invalid array length" error.

While the chart itself isn't meaningful when it only has 1 value, it is a use case that will come up occasionally.

pomelo-alias commented 2 years ago

+1