How to Make Plotly.js or Chart.js Charts Responsive
Charts we make on web are often seen on mobile devices. Then, the charts need to be responsive to the relatively small size of the mobile device. Charts made with Plotly.js or Chart.js are responsive in nature, but they both have the same problems: the charts look crowded on small screen and long title will be trucated on both the front end and back end.
Also, when there are a lot of data points, the charts or plots will look even more crowded.
Solutions
I will add another <div> tag around the chart and assgin overflow scroll
CSS property to it. And I will set the min-width for the original plot or
chart container so that the chart can be scrolled on small screen.
Non-responsive:
Responsive:
Responsive:
Plotly.js
<div id="myPlot"></div>
Chart.js
<canvas id="myChart"></canvas>
Which is better?
Chart.js' charts look beter on small screen, and are easier to scroll on mobile device with responsive design. It is easier to mis-click on the Plotly.js charts and accidentally zoom in, which is annoying. Chart.js does not have this problem.
Comments
Post a Comment