Improved JavaScript for displaying graphs in dashboard