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.
true
Daru::View.plotting_library = :highcharts
:highcharts
opts = {
chart: {defaultSeriesType: 'line'},
title: {
text: 'Solar Employment Growth by Sector, 2010-2016'
},
subtitle: {
text: 'Source: thesolarfoundation.com'
},
yAxis: {
title: {
text: 'Number of Employees'
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
plotOptions: {
# this is not working. Find the bug
# series: {
# pointStart: 43934
# }
},
}
line_1 = Daru::View::Plot.new ([])
#<Daru::View::Plot:0x007fd4c3b67548 @data=[], @options={}, @adapter=Daru::View::Adapter::HighchartsAdapter, @chart=#<LazyHighCharts::HighChart:0x007fd4c3b67368 @series_data=[{:type=>nil, :name=>nil, :data=>[]}], @options={}, @html_options={}, @placeholder="graph">>
line_1.chart.options = opts
line_1.chart.series_data = ([{
name: 'Installation',
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
}, {
name: 'Manufacturing',
data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
}, {
name: 'Sales & Distribution',
data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
}, {
name: 'Project Development',
data: [nil, nil, 7988, 12169, 15112, 22452, 34400, 34227]
}, {
name: 'Other',
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
}])
line_1.show_in_iruby
# after saving chart is displayed. Todo: find the bug
line_2= Daru::View::Plot.new
# line chart : chart with data-labels
opts = {
chart: {
type: 'line'
},
title: {
text: 'Monthly Average Temperature'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Temperature (°C)'
}
},
plotOptions: {
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: false
}
},
}
series_dt = ([{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.4, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}, {
name: 'London',
data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8]
}])
line_2.chart.options = opts;
line_2.chart.series_data = series_dt
line_2.show_in_iruby
# after saving chart is displayed. Todo: find the bug
# problem in this. don't run
# line chart : chart with data-labels
contents = [
["201352",0.7695],
["201353",0.7648],
["201354",0.7645],
["201355",0.7638],
["201356",0.7549],
["201357",0.7562],
["201359",0.7574],
["2013510",0.7543],
["2013511",0.7510],
["2013512",0.7498],
]
opts = {
chart: {
zoomType: 'x'
},
title: {
text: 'USD to EUR exchange rate over time'
},
subtitle: {
text: "document.ontouchstart === undefined ?
'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in'".js_code
},
# xAxis: {
# type: 'datetime' # for date time in javascript. currently not
# working
# },
yAxis: {
title: {
text: 'Exchange rate'
}
},
legend: {
enabled: false
},
plotOptions: {
area: {
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
# stops: [
# [0, "Highcharts.getOptions().colors[0]".js_code],
# [1, "Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')".js_code]
# ]
},
marker: {
radius: 2
},
# lineWidth: 1,
states: {
hover: {
lineWidth: 10
}
},
threshold: nil
}
},
}
series_dt = ([{
type: 'area',
name: 'USD to EUR',
data: contents
}])
line_3 = Daru::View::Plot.new
line_3.chart.options = opts;
line_3.chart.series_data = series_dt
line_3.show_in_iruby
# after saving chart is displayed. Todo: find the bug