表单: RailsNotes
用户: dreamable
创建日期: 2020-11-25 07:56:50 UTC
更新日期: 2021-03-29 23:45:38 UTC
引用:(Table ID 3, Record ID 8)

标题 :
Rails chart
笔记 :

chartkick

  1. installation

    # Add this line to your application's Gemfile:
    gem "chartkick" # This is not optional. Without it, function (e.g. line_chart) won't work even if js is ready. 
    # For Rails 6 / Webpacker, run:
    yarn add chartkick chart.js
    # And in app/javascript/packs/application.js, add:
    require("chartkick")
    require("chart.js")
    
  2. chart library

  3. Google chart

    • Load JS <%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" %>
    • Get an API Key
      1. To use google geo_chart, need a API key. (Seems OK for timeline chart).
      2. get a key
      3. AIzaSyCo0AKH9n0-vu92BsU9TwUDKjpmi6c8HZU
    • Set it

      <script type="text/javascript">
      google.charts.load('current', {
      'packages':['geochart'],
      'mapsApiKey': 'AIzaSyCo0AKH9n0-vu92BsU9TwUDKjpmi6c8HZU'
      });
      </script>
      
    • NOTE: I tried to set it in config/initializer/chartkick.rb

      Chartkick.options = {
      language: "en",
      mapsApiKey: "AIzaSyCo0AKH9n0-vu92BsU9TwUDKjpmi6c8HZU", // NOT WORK
      height: "400px", // SEEMS WORK
      colors: ["#b00", "#666"]
      }
      Chartkick.configure({language: "de", mapsApiKey: "..."}) // ERROR to load, no configure function. 
      
标签: