Class: Highcharts::Chart

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/opal/highcharts/chart.rb,
lib/opal/highcharts/base.rb

Overview

Ruby wrapper for Highcharts.Chart.js

See Also:

Author:

  • Colin Gunn

Instance Method Summary collapse

Methods included from Base

included

Constructor Details

#initialize(options_or_native) ⇒ Chart

Creates a Highcharts or Highstock chart.

If the argument is a native object it is wrapped otherwise a new native chart is created and wrapped. Highcharts.Map is not currently supported.

Parameters:

  • options_or_native (Hash, Native)

Options Hash (options_or_native):

  • :mode (Symbol)

    Either :chart, :stock, :map

  • :chart (Hash)

    and others per Highcharts docs

See Also:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/opal/highcharts/chart.rb', line 23

def initialize(options_or_native)
  if native?(options_or_native)
    super(options_or_native)
  else
    options = options_or_native.to_h.dup
    case mode = options.delete(:mode) || :chart
      when :chart
        super(`new Highcharts.Chart( #{ options.to_n } )`)
      when :stock
        super(`new Highcharts.stockChart( #{ options.to_n } )`)
      when :map
        raise UnsupportedFeature, "#{__FILE__}[#{__LINE__}] #{self.class.name}##{__method__} : chart mode : '#{mode}' (Highcharts.Map)"
        # super(`new Highcharts.Map( #{ options.to_n } )`)
      else
        raise ArgumentError, "#{__FILE__}[#{__LINE__}] #{self.class.name}##{__method__} : invalid chart mode '#{mode}'"
    end
  end
end

Instance Method Details

#getAxis, ...

Returns a chart element for a given a id.

Parameters:

  • id (String)

    the id of the chart element as set in configuration options

Returns:

See Also:



85
# File 'lib/opal/highcharts/chart.rb', line 85

alias_native :get

#get_svgString Also known as: svg

Returns an SVG string representing the chart. Highcharts exporting module required.

Parameters:

  • options (Hash)

    additional options

Returns:

  • (String)

See Also:



92
# File 'lib/opal/highcharts/chart.rb', line 92

alias_native :get_svg, :getSVG

#optionsHighcharts::Options

Returns the current configuration options of the chart.



98
# File 'lib/opal/highcharts/chart.rb', line 98

alias_native :options, :options, as: Options

#rendererHighcharts::Renderer

Returns the renderer for the chart.



118
# File 'lib/opal/highcharts/chart.rb', line 118

alias_native :renderer, :renderer, as: Renderer

#seriesArray<Series>

Returns an array of the series in the chart.



130
# File 'lib/opal/highcharts/chart.rb', line 130

alias_native :series, :series, as_array_of: Series

#subtitle=(string_or_hash, redraw = true) ⇒ Object

Change the subtitle (but not title) of the chart.

Parameters:

  • string_or_hash (String, Hash)

    string_or_hash If a string, then only the subtitle text will be changed. If a hash it should contain title options.

  • redraw (Boolean) (defaults to: true)

    optional, whether to redraw immediately, defaults to true

See Also:



152
153
154
155
# File 'lib/opal/highcharts/chart.rb', line 152

def subtitle=(string_or_hash, redraw = true)
  t = string_or_hash.is_a?(String) ? {text: string_or_hash} : string_or_hash.to_h
  set_title(nil, t, redraw)
end

#title=(string_or_hash, redraw = true) ⇒ Object

Change the title (but not subtitle) of the chart.

Parameters:

  • string_or_hash (String, Hash)

    If a string, then only the title text will be changed. If a hash it should contain title options.

  • redraw (Boolean) (defaults to: true)

    optional, whether to redraw immediately, defaults to true

See Also:



141
142
143
144
# File 'lib/opal/highcharts/chart.rb', line 141

def title=(string_or_hash, redraw = true)
  t = string_or_hash.is_a?(String) ? {text: string_or_hash} : string_or_hash.to_h
  set_title(t, nil, redraw)
end