Chart.js is a very popular JavaScript library for making charts. A timeline is a very popular type of chart. It looks like chart.js can make many different types of charts, except timelines. Is it possible to make a timeline with chart.js?
I was also searching for a way to draw a timeline/gantt diagram with chartjs 3 (in my case react-chartjs-2) but I couldn't find a good example that would fulfill all my needs.
Date as start and endSo I started experimenting with the horizontal stacked bar chart and got everything I needed. I was able to format and stack the data to fulfill all my needs without any fancy library, just chartjs 3 and data formatting. In my application I also created horizontal scrolling by filtering data, which works quite well.
I used the Stacked Bar Chart with Groups and the Horizontal Bar Chart as a starting point.
These information are essential to make it work correctly:
stack are absolute values, all following values of the same stack must be relative to the end of the previous barskipNull propertydisplay function of the datalabels options in order to hide all datalabels with null valuesI created a basic example in codesandbox:
Basic Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With