Table: RailsNotes
User: dreamable
Created at: 2020-11-25 07:56:50 UTC
Updated at: 2021-03-29 23:45:38 UTC
Reference:(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. 
      
Tag: