前提・実現したいこと
本番環境とローカル環境のhartkickのグラフのレイアウトが違います。
具体的には本番環境の方が正しくて開発環境が間違っていいます。
このようなグラフにしたいです。
開発環境が合ってて、本番環境が違うならコンパイルの関係がとかあるでしょうけど、
本番環境が合ってて、開発環境がその見た目にならないので困っています。
発生している問題・エラーメッセージ
エラーメッセージ
該当のソースコード
ruby
1gemfile 2 3gem 'chartkick' 4gem 'groupdate' 5gem 'rails-i18n' 6gem 'lazy_high_charts' 7
ruby
1グラフが表示されているview 2 3 <div class="right-content-post"> 4 <div class="right-content-upper"> 5 <%= pie_chart @spending_data.group(:category).sum(:price), thousands: ",", width: "450px", height:"450px", class:"date-graph", library: {title: {text: "今月の支出 計 #{@spending_sum}円"}} %> 6 </div>
ruby
1application.js 2require("chart.js") 3require("chartkick").use(require("highcharts"))
ruby
1config/initializers/chartkick.rb 2 3Chartkick.options = { 4 donut: true, # ドーナツグラフ 5 width: '400px', 6 colors: [ "#769fcd", 7 "#b9d7ea", 8 "#d6e6f2", 9 "#f7fbfc", 10 ], 11 message: {empty: "データがありません"}, 12 thousands: ",", 13 suffix: "円", 14 legend: false, # 凡例非表示 15 library: { # ここからHighchartsのオプション 16 title: { # タイトル表示(ここでは、グラフの真ん中に配置して,viewでデータを渡しています。*後述) 17 align: 'center', 18 verticalAlign: 'middle', 19 }, 20 chart: { 21 backgroundColor: 'none', 22 plotBorderWidth: 0, 23 plotShadow: false 24 }, 25 plotOptions: { 26 pie: { 27 dataLabels: { 28 enabled: true, 29 distance: -40, # ラベルの位置調節 30 allowOverlap: false, # ラベルが重なったとき、非表示にする 31 style: { #ラベルフォントの設定 32 color: '#555', 33 textAlign: 'center', 34 textOutline: 0, #デフォルトではラベルが白枠で囲まれていてダサいので消す 35 } 36 }, 37 size: '110%', 38 innerSize: '60%', # ドーナツグラフの中の円の大きさ 39 borderWidth: 0, 40 } 41 }, 42 } 43}
config/environments/development.rb Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false # Show full error reports. config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. if Rails.root.join('tmp', 'caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false config.cache_store = :null_store end # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false config.action_mailer.perform_caching = false # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. config.assets.debug = true # Suppress logger output for asset requests. config.assets.quiet = true # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker end
ruby
1config/environments/production.rb 2 3 4Rails.application.configure do 5 # Settings specified here will take precedence over those in config/application.rb. 6 7 # Code is not reloaded between requests. 8 config.cache_classes = true 9 10 # Eager load code on boot. This eager loads most of Rails and 11 # your application in memory, allowing both threaded web servers 12 # and those relying on copy on write to perform better. 13 # Rake tasks automatically ignore this option for performance. 14 config.eager_load = true 15 16 # Full error reports are disabled and caching is turned on. 17 config.consider_all_requests_local = false 18 config.action_controller.perform_caching = true 19 20 # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] 21 # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). 22 # config.require_master_key = true 23 24 # Disable serving static files from the `/public` folder by default since 25 # Apache or NGINX already handles this. 26 config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 27 28 # Compress CSS using a preprocessor. 29 # config.assets.css_compressor = :sass 30 31 # Do not fallback to assets pipeline if a precompiled asset is missed. 32 config.assets.compile = true 33 34 # Enable serving of images, stylesheets, and JavaScripts from an asset server. 35 # config.action_controller.asset_host = 'http://assets.example.com' 36 37 # Specifies the header that your server uses for sending files. 38 # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 39 # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 40 41 # Store uploaded files on the local file system (see config/storage.yml for options). 42 config.active_storage.service = :local 43 44 # Mount Action Cable outside main process or domain. 45 # config.action_cable.mount_path = nil 46 # config.action_cable.url = 'wss://example.com/cable' 47 # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ] 48 49 # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 50 # config.force_ssl = true 51 52 # Use the lowest log level to ensure availability of diagnostic information 53 # when problems arise. 54 config.log_level = :debug 55 56 # Prepend all log lines with the following tags. 57 config.log_tags = [ :request_id ] 58 59 # Use a different cache store in production. 60 # config.cache_store = :mem_cache_store 61 62 # Use a real queuing backend for Active Job (and separate queues per environment). 63 # config.active_job.queue_adapter = :resque 64 # config.active_job.queue_name_prefix = "expenses_production" 65 66 config.action_mailer.perform_caching = false 67 68 # Ignore bad email addresses and do not raise email delivery errors. 69 # Set this to true and configure the email server for immediate delivery to raise delivery errors. 70 # config.action_mailer.raise_delivery_errors = false 71 72 # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 73 # the I18n.default_locale when a translation cannot be found). 74 config.i18n.fallbacks = true 75 76 # Send deprecation notices to registered listeners. 77 config.active_support.deprecation = :notify 78 79 # Use default logging formatter so that PID and timestamp are not suppressed. 80 config.log_formatter = ::Logger::Formatter.new 81 82 # Use a different logger for distributed setups. 83 # require 'syslog/logger' 84 # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 85 86 if ENV["RAILS_LOG_TO_STDOUT"].present? 87 logger = ActiveSupport::Logger.new(STDOUT) 88 logger.formatter = config.log_formatter 89 config.logger = ActiveSupport::TaggedLogging.new(logger) 90 end 91 92 # Do not dump schema after migrations. 93 config.active_record.dump_schema_after_migration = false 94 95 # Inserts middleware to perform automatic connection switching. 96 # The `database_selector` hash is used to pass options to the DatabaseSelector 97 # middleware. The `delay` is used to determine how long to wait after a write 98 # to send a subsequent read to the primary. 99 # 100 # The `database_resolver` class is used by the middleware to determine which 101 # database is appropriate to use based on the time delay. 102 # 103 # The `database_resolver_context` class is used by the middleware to set 104 # timestamps for the last write to the primary. The resolver uses the context 105 # class timestamps to determine how long to wait before reading from the 106 # replica. 107 # 108 # By default Rails will store a last write timestamp in the session. The 109 # DatabaseSelector middleware is designed as such you can define your own 110 # strategy for connection switching and pass that into the middleware through 111 # these configuration options. 112 # config.active_record.database_selector = { delay: 2.seconds } 113 # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver 114 # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session 115end 116
試したこと
config/initializers/chartkick.rbのファイル内のデータが読み込まれていない? ではなぜ、本番環境では読み込まれている?(本番で読み込まれないなら、なんとなくわかるが、、) config/environments/development.rbにconfig/initializers/chartkick.rbのファイルが読まれていない? 初心者ですが、どなたかご教授よろしくお願いします。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。