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_class: 'stock',
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Stock Price'
}
}
series_dt = [
{
name: 'AAPL',
data: [
[1147651200000,67.79],
[1147737600000,64.98],
[1147824000000,65.26],
[1149120000000,62.17],
[1149206400000,61.66],
[1149465600000,60.00],
[1149552000000,59.72],
[1157932800000,72.50],
[1158019200000,72.63],
[1158105600000,74.20],
[1158192000000,74.17],
[1158278400000,74.10],
[1158537600000,73.89],
[1170288000000,84.74],
[1170374400000,84.75],
[1174953600000,95.46],
[1175040000000,93.24],
[1175126400000,93.75],
[1175212800000,92.91],
[1180051200000,113.62],
[1180396800000,114.35],
[1180483200000,118.77],
[1180569600000,121.19],
],
tooltip: {
valueDecimals: 2
}
}
]
line_series = Daru::View::Plot.new
line_series.chart.options = opts;
line_series.chart.series_data = series_dt
line_series.show_in_iruby
opts = {
chart_class: 'stock',
rangeSelector: {
selected: 0
},
title: {
text: 'USD to EUR exchange rate'
},
tooltip: {
style: {
width: '200px'
},
valueDecimals: 4,
shared: true
},
yAxis: {
title: {
text: 'Exchange rate'
}
}
}
series_dt = [
{
name: 'USD to EUR',
data: [
[
1167609600000,
0.7537
],
[
1167696000000,
0.7537
],
[
1167782400000,
0.7559
],
[
1167868800000,
0.7631
],
[
1167955200000,
0.7644
],
[
1168214400000,
0.769
],
[
1168300800000,
0.7683
],
[
1168387200000,
0.77
],
[
1196035200000,
0.6737
],
[
1196121600000,
0.6724
],
[
1196208000000,
0.6782
],
[
1196294400000,
0.6786
],
[
1196380800000,
0.6776
],
[
1196640000000,
0.6819
],
[
1196726400000,
0.6785
],
[
1196812800000,
0.6794
],
[
1196899200000,
0.6872
],
[
1196985600000,
0.6827
],
[
1197244800000,
0.6795
],
[
1513209600000,
0.8443
],
[
1513296000000,
0.8471
],
[
1513555200000,
0.8479
],
[
1513641600000,
0.8459
],
[
1513728000000,
0.8443
],
[
1513814400000,
0.8433
],
[
1513900800000,
0.8438
],
[
1514332800000,
0.8408
],
[
1514419200000,
0.838
],
[
1514505600000,
0.8339
]
],
id: 'dataseries'
# the event marker flags
}, {
type: 'flags',
data: [{
title: 'C',
text: 'Stocks fall on Greece, rate concerns; US dollar dips'
}, {
title: 'D',
text: 'Zimbabwe ditches \'worthless\' currency for the US dollar '
}, {
title: 'E',
text: 'US Dollar Declines Over the Week on Rate Timeline'
}, {
title: 'F',
text: 'Greek Negotiations Take Sharp Turn for Worse, US Dollar set to Rally '
}, {
title: 'G',
text: 'Euro records stunning reversal against dollar'
}, {
title: 'H',
text: 'Surging US dollar curbs global IT spend'
}],
onSeries: 'dataseries',
shape: 'circlepin',
width: 16
}
]
flag_marking = Daru::View::Plot.new
flag_marking.chart.options = opts;
flag_marking.chart.series_data = series_dt
flag_marking.show_in_iruby
opts = {
chart_class: 'stock',
title: {
text: 'AAPL stock price by minute'
},
rangeSelector: {
buttons: [{
type: 'hour',
count: 1,
text: '1h'
}, {
type: 'day',
count: 1,
text: '1D'
}, {
type: 'all',
count: 1,
text: 'All'
}],
selected: 1,
}
}
series_dt = [
{
name: 'AAPL',
type: 'candlestick',
data: [
[1317888000000,372.5101,375,372.2,372.52],
[1317888060000,372.4,373,372.01,372.16],
[1317888120000,372.16,372.4,371.39,371.62],
[1317888180000,371.62,372.16,371.55,371.75],
[1317888240000,371.75,372.4,371.57,372],
[1317888300000,372,372.3,371.8,372.24],
[1317888360000,372.22,372.45,372.22,372.3],
[1317910560000,376.68,376.95,376.68,376.85],
[1317910620000,376.85,376.85,376.53,376.76],
[1317910680000,376.62,377.19,376.49,376.99],
[1317910740000,376.98,377.99,376.76,377.99],
[1317910800000,377.989,378.05,377.38,377.87],
[1318242780000,383.52,383.86,383.41,383.86],
[1318242840000,383.85,383.94,383.4,383.48],
[1318242900000,383.54,384.4,383.481,384.136],
[1318242960000,384.14,384.39,383.87,384.19],
[1318243020000,384.246,384.3,383.34,383.5],
[1318243080000,383.4335,383.83,383.41,383.5],
[1318243140000,383.5001,383.59,383.2,383.2501],
[1318243200000,383.2276,383.252,382.75,383.059],
[1318427580000,406.23,406.402,406.05,406.09],
[1318427640000,406.12,406.19,405.97,406.1072],
[1318427700000,406.111,406.54,406.111,406.54],
[1318427760000,406.49,406.53,406.19,406.332],
[1318427820000,406.31,406.49,406.24,406.349],
[1318607700000,420.58,421.14,420.575,421.0975],
[1318607760000,421.07,421.49,420.7,421.46],
[1318607820000,421.4601,421.71,421.36,421.69],
[1318607880000,421.69,421.94,421.663,421.94],
[1318607940000,421.94,422,421.8241,422]
],
tooltip: {
valueDecimals: 2
}
}
]
candle_stick = Daru::View::Plot.new
candle_stick.chart.options = opts;
candle_stick.chart.series_data = series_dt
candle_stick.show_in_iruby
opts = {
chart_class: 'stock',
chart: {
height: 400
},
title: {
text: 'Highstock Responsive Chart'
},
subtitle: {
text: 'Click small/large buttons or change window size to test responsiveness'
},
rangeSelector: {
selected: 1
},
responsive: {
rules: [{
condition: {
maxWidth: 500
},
chartOptions: {
chart: {
height: 300
},
navigator: {
enabled: false
}
}
}]
}
}
series_dt = [
{
name: 'AAPL Stock Price',
data: [
[1147651200000,67.79],
[1147737600000,64.98],
[1147824000000,65.26],
[1149120000000,62.17],
[1149206400000,61.66],
[1149465600000,60.00],
[1149552000000,59.72],
[1157932800000,72.50],
[1158019200000,72.63],
[1158105600000,74.20],
[1158192000000,74.17],
[1158278400000,74.10],
[1158537600000,73.89],
[1170288000000,84.74],
[1170374400000,84.75],
[1174953600000,95.46],
[1175040000000,93.24],
[1175126400000,93.75],
[1175212800000,92.91],
[1180051200000,113.62],
[1180396800000,114.35],
[1180483200000,118.77],
[1180569600000,121.19],
],
type: 'area',
tooltip: {
valueDecimals: 2
},
threshold: nil
}
]
line_series = Daru::View::Plot.new
line_series.chart.options = opts;
line_series.chart.series_data = series_dt
line_series.show_in_iruby
opts = {
chart_class: 'stock',
title: {
text: 'AAPL stock price by minute'
},
subtitle: {
text: 'Using ordinal X axis'
},
xAxis: {
gapGridLineWidth: 0
},
rangeSelector: {
buttons: [{
type: 'hour',
count: 1,
text: '1h'
}, {
type: 'day',
count: 1,
text: '1D'
}, {
type: 'all',
count: 1,
text: 'All'
}],
selected: 1,
inputEnabled: false
}
}
series_dt = [
{
name: 'AAPL',
type: 'area',
data: [
[1317888000000,372.5101,375,372.2,372.52],
[1317888060000,372.4,373,372.01,372.16],
[1317888120000,372.16,372.4,371.39,371.62],
[1317888180000,371.62,372.16,371.55,371.75],
[1317888240000,371.75,372.4,371.57,372],
[1317888300000,372,372.3,371.8,372.24],
[1317888360000,372.22,372.45,372.22,372.3],
[1317910560000,376.68,376.95,376.68,376.85],
[1317910620000,376.85,376.85,376.53,376.76],
[1317910680000,376.62,377.19,376.49,376.99],
[1317910740000,376.98,377.99,376.76,377.99],
[1317910800000,377.989,378.05,377.38,377.87],
[1318242780000,383.52,383.86,383.41,383.86],
[1318242840000,383.85,383.94,383.4,383.48],
[1318242900000,383.54,384.4,383.481,384.136],
[1318242960000,384.14,384.39,383.87,384.19],
[1318243020000,384.246,384.3,383.34,383.5],
[1318243080000,383.4335,383.83,383.41,383.5],
[1318243140000,383.5001,383.59,383.2,383.2501],
[1318243200000,383.2276,383.252,382.75,383.059],
[1318427580000,406.23,406.402,406.05,406.09],
[1318427640000,406.12,406.19,405.97,406.1072],
[1318427700000,406.111,406.54,406.111,406.54],
[1318427760000,406.49,406.53,406.19,406.332],
[1318427820000,406.31,406.49,406.24,406.349],
[1318607700000,420.58,421.14,420.575,421.0975],
[1318607760000,421.07,421.49,420.7,421.46],
[1318607820000,421.4601,421.71,421.36,421.69],
[1318607880000,421.69,421.94,421.663,421.94],
[1318607940000,421.94,422,421.8241,422]
],
gapSize: 5,
tooltip: {
valueDecimals: 2
},
threshold: nil
}
]
intraday_area = Daru::View::Plot.new
intraday_area.chart.options = opts;
intraday_area.chart.series_data = series_dt
intraday_area.show_in_iruby