/
sharePricePlot3.R
77 lines (67 loc) · 3.08 KB
/
sharePricePlot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
sharePricePlot3 <- function(data){
data <- na.exclude(data)
data <- transform(data, date = as.numeric(as.Date(date)) * 86400000)
a <- rCharts::Highcharts$new()
a$yAxis(list(
list(title = list(text = "Share Price"),max = max(data$close)*1.05,opposite = TRUE,height = 300,
labels = list(
style = list(
fontWeight = "bold")
)
),
list(title = list(text = "ADL"),opposite = FALSE,
top = 325,offset = 0,height = 125,
labels = list(
style = list(
fontWeight = "bold")
)
),
list(title = list(text = "Volume"),opposite = TRUE, plotBands = list(color = "black",from = 100, to = 110),
top = 475,offset = 0,height = 125,
labels = list(
style = list(
fontWeight = "bold")
)
)
)
)
a$xAxis(type = "datetime")
a$series(type = "line",name = "Share Price",
data = toJSONArray2(data[,c("date","close")],json = F,names = F),
color = "orange",
yAxis = 0
)
a$series(type = "line",name = "Parabolic SAR",
data = toJSONArray2(data[,c("date","sar1")],json = F,names = F) ,
lineWidth = 0,
marker = list(enabled = TRUE,radius = 3),
yAxis = 0
)
a$series(type = "line",name = "ADL",
data = toJSONArray2(data[,c("date","volume")],json = F,names = F),
yAxis = 2
)
a$series(type = "line",name = "Volume",
data = toJSONArray2(data[,c("date","ADL")],json = F,names = F),
yAxis = 1
)
a$tooltip(crosshairs = list(T,F),
shared=TRUE,
formatter = "#! function() {
var d = new Date(this.x);
d = d.toLocaleDateString();
d = '<strong>' + d + '</strong>';
$.each(this.points,function(){
d += '<br>' + this.series.name + ': ' + '<strong>' + Highcharts.numberFormat(this.y,2,'.') + '</strong>';
})
return (d);
}!#"
)
a$legend(align = "right",verticalAlign = "center",
layout = "vertical",itemMarginTop = 10,x = 10,
floating = FALSE,backgroundColor = "white",
labelFormatter="#! function () {return this.name;}!#")
a$plotOptions(series = list(pointPadding = 0,groupPadding = 0.2,marker = list(enabled=FALSE)))
a$chart(zoomType = 'x',width = 1000, height = 650,plotBorderWidth = 0.5,plotBorderColor="black")
a
}