In [1]:
require 'daru/view'
Install the spreadsheet gem version ~>1.1.1 for using spreadsheet functions.

Install the mechanize gem version ~>2.7.5 for using mechanize functions.
Out[1]:
true
In [2]:
Daru::View.plotting_library = :highcharts
Out[2]:
:highcharts
In [3]:
data = [[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1],
              [50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]]
    opts = {
      chart:  {
              type: 'spline',
              inverted: true
          },
      title: {
          text: 'Atmosphere Temperature by Altitude'
      },
      subtitle: {
          text: 'According to the Standard Atmosphere Model'
      },
      xAxis: {
          reversed: false,
          title: {
              enabled: true,
              text: 'Altitude'
          },
          labels: {
              formatter: "function () {
                  return this.value + 'km';
              }".js_code
          },
          maxPadding: 0.05,
          showLastLabel: true
      },
      yAxis:{
          title: {
              text: 'Temperature'
          },
          labels: {
              formatter: "function () {
                  return this.value + '°';
              }".js_code
          },
          lineWidth: 2
      },
      legend:{
          enabled: false
      },
      tooltip:{
          headerFormat: '<b>{series.name}</b><br/>',
          pointFormat: '{point.x} km: {point.y}°C'
      },
      plotOptions:{
          spline: {
              marker: {
                  enable: false
              }
          }
      },
    }
Out[3]:
{:chart=>{:type=>"spline", :inverted=>true}, :title=>{:text=>"Atmosphere Temperature by Altitude"}, :subtitle=>{:text=>"According to the Standard Atmosphere Model"}, :xAxis=>{:reversed=>false, :title=>{:enabled=>true, :text=>"Altitude"}, :labels=>{:formatter=>"function () {\n                  return this.value + 'km';\n              }"}, :maxPadding=>0.05, :showLastLabel=>true}, :yAxis=>{:title=>{:text=>"Temperature"}, :labels=>{:formatter=>"function () {\n                  return this.value + '°';\n              }"}, :lineWidth=>2}, :legend=>{:enabled=>false}, :tooltip=>{:headerFormat=>"<b>{series.name}</b><br/>", :pointFormat=>"{point.x} km: {point.y}°C"}, :plotOptions=>{:spline=>{:marker=>{:enable=>false}}}}
In [4]:
chart1 = Daru::View::Plot.new data, opts
Out[4]:
#<Daru::View::Plot:0x007fdbc73e4a68 @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007fdbc73e49a0 @series_data=[{:type=>nil, :name=>nil, :data=>[[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1], [50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]]}], @options={:chart=>{:type=>"spline", :inverted=>true}, :title=>{:text=>"Atmosphere Temperature by Altitude"}, :subtitle=>{:text=>"According to the Standard Atmosphere Model"}, :xAxis=>{:reversed=>false, :title=>{:enabled=>true, :text=>"Altitude"}, :labels=>{:formatter=>"function () {\n                  return this.value + 'km';\n              }"}, :maxPadding=>0.05, :showLastLabel=>true}, :yAxis=>{:title=>{:text=>"Temperature"}, :labels=>{:formatter=>"function () {\n                  return this.value + '°';\n              }"}, :lineWidth=>2}, :legend=>{:enabled=>false}, :tooltip=>{:headerFormat=>"<b>{series.name}</b><br/>", :pointFormat=>"{point.x} km: {point.y}°C"}, :plotOptions=>{:spline=>{:marker=>{:enable=>false}}}}, @html_options={}, @placeholder="graph">>
In [5]:
chart1.show_in_iruby
Out[5]:
In [6]:
# add another chart 
chart1.add_series({
        :data => [[10, 15], [20, -50], [30, -56.5], [40, -46.5], [50, -22.1],
              [55, -2.5], [65, -27.7], [80, -55.7], [90, -76.5]]})
Out[6]:
In [7]:
# add another chart
opts = {
  :type=> 'pie',:name=> 'Total consumption',
  :data=> [
    {:name=> 'Jane', :y=> 13, :color=> 'red'},
    {:name=> 'John', :y=> 23,:color=> 'green'},
    {:name=> 'Joe', :y=> 19,:color=> 'blue'}
  ],
  :center=> [100, 150], :size=> 100, :showInLegend=> false
}
chart1.add_series(opts)
Out[7]:
In [9]:
chart1.chart.class
Out[9]:
LazyHighCharts::HighChart
In [14]:
chart1.chart.series_data
Out[14]:
[{:type=>nil, :name=>nil, :data=>[[0, 15], [10, -50], [20, -56.5], [30, -46.5], [40, -22.1], [50, -2.5], [60, -27.7], [70, -55.7], [80, -76.5]]}, {:data=>[[10, 15], [20, -50], [30, -56.5], [40, -46.5], [50, -22.1], [55, -2.5], [65, -27.7], [80, -55.7], [90, -76.5]], :name=>nil}, {:type=>"pie", :name=>"Total consumption", :data=>[{:name=>"Jane", :y=>13, :color=>"red"}, {:name=>"John", :y=>23, :color=>"green"}, {:name=>"Joe", :y=>19, :color=>"blue"}], :center=>[100, 150], :size=>100, :showInLegend=>false}]
In [15]:
chart1.chart.series_data[2]
Out[15]:
{:type=>"pie", :name=>"Total consumption", :data=>[{:name=>"Jane", :y=>13, :color=>"red"}, {:name=>"John", :y=>23, :color=>"green"}, {:name=>"Joe", :y=>19, :color=>"blue"}], :center=>[100, 150], :size=>100, :showInLegend=>false}
In [16]:
# all te series options can be updated
# removing last pie chart, that was added
chart1.chart.series_data[2] = {}
Out[16]:
{}
In [18]:
chart1.chart
Out[18]:
In [19]:
chart1.chart.options
Out[19]:
{:chart=>{:type=>"spline", :inverted=>true, :renderTo=>"cwjfdubaqkv"}, :title=>{:text=>"Atmosphere Temperature by Altitude"}, :subtitle=>{:text=>"According to the Standard Atmosphere Model"}, :xAxis=>{:reversed=>false, :title=>{:enabled=>true, :text=>"Altitude"}, :labels=>{:formatter=>"function () {\n                  return this.value + 'km';\n              }"}, :maxPadding=>0.05, :showLastLabel=>true}, :yAxis=>{:title=>{:text=>"Temperature"}, :labels=>{:formatter=>"function () {\n                  return this.value + '°';\n              }"}, :lineWidth=>2}, :legend=>{:enabled=>false}, :tooltip=>{:headerFormat=>"<b>{series.name}</b><br/>", :pointFormat=>"{point.x} km: {point.y}°C"}, :plotOptions=>{:spline=>{:marker=>{:enable=>false}}}}
In [20]:
# all the `options` can be set or updated
chart1.chart.options[:chart][:inverted] = false
Out[20]:
false
In [21]:
chart1.chart # or do chart1.show_in_iruby
Out[21]:
In [22]:
# can be updated
chart1.chart.placeholder
Out[22]:
"graph"
In [23]:
# can be updated
chart1.chart.html_options
Out[23]:
{:id=>"fpyaihjuvwk"}
In [43]:
chart1.chart.html_options[:style] = "opacity: 0.5; height: 720px; width: 1020px"
Out[43]:
"opacity: 0.5; height: 720px; width: 1020px"
In [44]:
chart1.chart
Out[44]:
In [ ]: