簡體   English   中英

無法使用Chartkick.js和Mysql顯示Rails圖-給出時區問題

[英]Not able to display a Rails graph using chartkick.js and Mysql - Giving timezone problems

嘗試顯示基於[ 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'

show.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>

Charts_controller.rb

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

我已經從安裝隨附的示例插入語句中加載了一些數據到MySQL時區表中。 不知道我在這里還想念什么。

這個對我有用。

  <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”

看來已經為您完成了幫助部分: 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM