Create Histogram Chart Using Chart.JS
Introduction
Chart.JS is a popular and free open-source JavaScript library for data visualization. However, Chart.JS does not natively support histogram.
In this blog post, I would like to quickly show how to use Chart.JS to create histogram chart in HTML.
Histogram Chart
Ideally, the input to histogram is an array of 1D data. Then we specify the bin size of the histogram and the number of samples in each bin will be counted by the histogram plot function. To create histogram using Chart.JS, because Chart.JS supports bar chart but does not natively support histogram, we would have to manually count the number of samples in each bin, and use the 2D counted data to create a bar chart, as if it were histogram chart.
HTML Histogram Chart
The histogram chart in HTML that we will create looks like as follows.
HTML Histogram Chart JavaScript
The HTML Histogram chart JavaScript code was mostly taken from the Chart.JS Histogram Series with some modifications.
1 |
|
References
Create Histogram Chart Using Chart.JS