0

我在尝试显示基于 [ https://richonrails.com/articles/charting-with-chartkick]在线教程的简单图表时出现以下错误。

这是我尝试点击在Rails 4应用程序中显示图表的页面时遇到的错误。看起来我缺少时区支持,MySQL但不确定如何安装。我位于US EST时区。我该如何解决这个问题?

安装的宝石:

gem 'chartkick'
gem 'groupdate'
gem 'active_median'

错误日志:

ActionView::Template::Error (Be sure to install time zone support - https://github.com/ankane/groupdate#for-mysql):
    3:   <!-- Line Chart - Single Series -->
    4:   <div class="col-xs-6">
    5:     <h3>Visits By Day</h3>
    6:     <%= line_chart @visits.group_by_day(:visited_at, format: "%B %d, %Y").count, discrete: true %>
    7:   </div>
    8:
    9: </div>
  app/views/charts/show.html.erb:6:in `_app_views_charts_show_html_erb__137374658_98254572'

显示.html.erb

<div class="row">

  <!-- Line Chart - Single Series -->
  <div class="col-xs-6">
    <h3>Visits By Day</h3>
    <%= line_chart @visits.group_by_day(:visited_at, format: "%B %d, %Y").count, discrete: true %>
  </div>

</div>

图表控制器.rb

class ChartsController < ApplicationController
  def show
    @visits = Visit.all
  end
end

我已经将安装附带的示例插入语句中的一些数据加载到 MySQL 时区表中。不知道我在这里还缺少什么。

4

2 回答 2

1

这个对我有用。

  <div class="col-xs-6">
    <h3>Visits By Day</h3>
    <%= line_chart @visits.group(:visited_at).count, discrete: true %>
  </div>

使用 MySQL 数据库:

insert into visits values(1,'Mexico',24,'2012-12-31','2012-12-31 11:30:45','2012-12-31 11:30:45');

日期格式: '2012-12-31'

于 2016-07-11T19:22:28.777 回答
0

看起来已经为您完成了一个帮助部分:https ://github.com/ankane/groupdate#for-mysql

你试过那个资源吗?它对你有用吗?

您可能还应该阅读 MySQL 的 TimeZone 部分,以帮助您解决问题并正确配置数据库:http: //dev.mysql.com/doc/refman/5.6/en/time-zone-support。 html

看起来 MySQL 也带有 time_zone 表。查看@ankane 关于使用 TimeZone 获得 MySQL 支持的要点:https ://gist.github.com/ankane/1d6b0022173186accbf0

于 2016-02-20T00:24:11.153 回答