Search code examples
javascriptjqueryruby-on-railscoffeescriptmorris.js

Morris chart only displayed after page refresh


My Morris Line chart is not showing on initial page load. Manually using the browser refresh will result in the chart displaying as expected. This is under Rails 5 and Chrome/Safari/Firefox. My coffeescript file.

jQuery ->
  Morris.Line({
    resize:true,
    parseTime:false,
    hideHover:true,
    xLabelAngle:45,
    ymin:100,
    ymax:300,
    element: 'game_averages'
    data: $('#game_averages').data('averages')
    xkey: 'game_title'
    ykeys: ['athlete','field']
    labels: ['Favorite','Field']}
  )

This is based on an old RailsCast http://railscasts.com/episodes/223-charts-graphs-revised


Solution

  • @caffinated.tech was right with their answer "This sounds like a problem with turbolinks - have a look at this answer "