module Node::Echarts

Constants

VERSION

Public Class Methods

chart(path, data, width=400, height=400) click to toggle source

Generate chart picture

Example:

>> chart("/home/foo/sample.png", {titile: {text: 'T1'},
                        xAxis: ['c'],
                        series: [{type: 'bar', data: [100]}]
                        },
         400, 400)

Arguments:
  path: (string)
  data: (hash)
  width: integer
  height: integer
# File lib/node/echarts.rb, line 20
def self.chart(path, data, width=400, height=400)
  cmd_str = "var echarts = require('echarts'); var Canvas = require('canvas'); var fs = require('fs'); #{@theme}; echarts.setCanvasCreator(function () { var canvas = new Canvas(#{width}, #{height}); return canvas; }); var chart = echarts.init(new Canvas(#{width}, #{height}), 'infographic'); chart.setOption(#{data.to_json.gsub("\"", "'")}); fs.writeFileSync('#{path}', chart.getDom().toBuffer()); process.exit()"
  `export export NODE_PATH=$(npm config get prefix)/lib/node_modules; node -e "#{cmd_str}"`
end
register_theme(path) click to toggle source

Register echarts theme by file

Example:

>> Node::Echarts.register_theme("/home/infographic")

Arguments:

path: (string)
# File lib/node/echarts.rb, line 32
def self.register_theme(path)
  @theme = File.read(path).
    gsub(/\/\/.*$/, '').  # remove comment
    gsub("\n", "").       # remove \n
    gsub(/\s+/, " ").     # compact blank
    gsub("\"", "'")       # replace " with '
end