HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function() {
2
3
// define chart
4
var chart = anychart.financial();
5
6
chart.title("Monthly Iranian crudle oil production");
7
8
// crosshair settings
9
var crosshair = chart.crosshair();
10
// enable crosshair
11
crosshair.enabled(true);
12
// set custom function for formatting x crossshair label
13
var xCrossLabel = crosshair.xLabel();
14
xCrossLabel.format(function(){
15
// get label data
16
var date = new Date(this.rawValue);
17
// get month from date
18
var month = date.toLocaleDateString("en-US", {month: "long"});
19
// get day from date
20
var day = date.toLocaleDateString("en-US", {day: "numeric"});
21
// get year from date
22
var year = date.toLocaleDateString("en-US", {year: "numeric"});
23
// format label content
24
return month + " " + day + ", " + year;
25
});
26
// set custom function for formatting y crossshair label
27
var yCrossLabel = crosshair.yLabel();
28
yCrossLabel.enabled(false);
29
30
crosshair.yStroke(null);
31
32
var xScale = chart.xScale();
33
xScale.minimum(Date.UTC(2011, 0, 1));
34
xScale.maximum(Date.UTC(2018, 1, 1));
35
var xTicks = chart.xScale().ticks();
36
xTicks.interval(0,4);
37
var xLabels = chart.xAxis().labels();
38
xLabels.format(function(){
39
var date = new Date(this["tickValue"]);
40
var options = {month: "short", year: "numeric"};
41
return date.toLocaleDateString("en-US", options);
42
});
43
44
var yScale = chart.yScale();
45
yScale.minimum(0);
46
47
chart.xScroller(true);
48
var xZoom = chart.xZoom();
49
xZoom.setToValues(Date.UTC(2014, 0, 1), Date.UTC(2018, 1, 1));
50
51
// set series data
52
var series = chart.line([
53
{x: Date.UTC(2011, 0, 01), value: 3.7},
54
{x: Date.UTC(2011, 1, 01), value: 3.7},
55
{x: Date.UTC(2011, 2, 01), value: 3.7},
56
{x: Date.UTC(2011, 3, 01), value: 3.6},
57
{x: Date.UTC(2011, 4, 01), value: 3.6},
58
{x: Date.UTC(2011, 5, 01), value: 3.5},
59
{x: Date.UTC(2011, 6, 01), value: 3.4},
60
{x: Date.UTC(2011, 7, 01), value: 3.4},
61
{x: Date.UTC(2011, 8, 01), value: 3.5},
62
{x: Date.UTC(2011, 9, 01), value: 3.3},
63
{x: Date.UTC(2011, 10, 01), value: 3.3},
64
{x: Date.UTC(2011, 11, 01), value: 3.2},
65
{x: Date.UTC(2012, 0, 01), value: 3.2},
66
{x: Date.UTC(2012, 1, 01), value: 3.2},
67
{x: Date.UTC(2012, 2, 01), value: 3.1},
68
{x: Date.UTC(2012, 3, 01), value: 3.1},
69
{x: Date.UTC(2012, 4, 01), value: 3.1},
70
{x: Date.UTC(2012, 5, 01), value: 3.0},
71
{x: Date.UTC(2012, 6, 01), value: 3.0},
72
{x: Date.UTC(2012, 7, 01), value: 2.9},
73
{x: Date.UTC(2012, 8, 01), value: 2.9},
74
{x: Date.UTC(2012, 9, 01), value: 2.8},
75
{x: Date.UTC(2012, 10, 01), value: 2.7},
76
{x: Date.UTC(2012, 11, 01), value: 2.7},
77
{x: Date.UTC(2013, 0, 01), value: 2.6},
78
{x: Date.UTC(2013, 1, 01), value: 2.6},
79
{x: Date.UTC(2013, 2, 01), value: 2.7},
80
{x: Date.UTC(2013, 3, 01), value: 2.7},
81
{x: Date.UTC(2013, 4, 01), value: 2.7},
82
{x: Date.UTC(2013, 5, 01), value: 2.7},
83
{x: Date.UTC(2013, 6, 01), value: 2.7},
84
{x: Date.UTC(2013, 7, 01), value: 2.7},
85
{x: Date.UTC(2013, 8, 01), value: 2.7},
86
{x: Date.UTC(2013, 9, 01), value: 2.7},
87
{x: Date.UTC(2013, 10, 01), value: 2.7},
88
{x: Date.UTC(2013, 11, 01), value: 2.7},
89
{x: Date.UTC(2014, 0, 01), value: 2.7},
90
{x: Date.UTC(2014, 1, 01), value: 2.75},
91
{x: Date.UTC(2014, 2, 01), value: 2.8},
92
{x: Date.UTC(2014, 3, 01), value: 2.85},
93
{x: Date.UTC(2014, 4, 01), value: 2.9},
94
{x: Date.UTC(2014, 5, 01), value: 2.9},
95
{x: Date.UTC(2014, 6, 01), value: 2.9},
96
{x: Date.UTC(2014, 7, 01), value: 2.9},
97
{x: Date.UTC(2014, 8, 01), value: 2.9},
98
{x: Date.UTC(2014, 9, 01), value: 2.9},
99
{x: Date.UTC(2014, 10, 01), value: 2.9},
100
{x: Date.UTC(2014, 11, 01), value: 2.9},
101
{x: Date.UTC(2015, 0, 01), value: 2.9},
102
{x: Date.UTC(2015, 1, 01), value: 2.9},
103
{x: Date.UTC(2015, 2, 01), value: 2.9},
104
{x: Date.UTC(2015, 3, 01), value: 2.9},
105
{x: Date.UTC(2015, 4, 01), value: 2.9},
106
{x: Date.UTC(2015, 5, 01), value: 2.9},
107
{x: Date.UTC(2015, 6, 01), value: 2.9},
108
{x: Date.UTC(2015, 7, 01), value: 2.9},
109
{x: Date.UTC(2015, 8, 01), value: 2.9},
110
{x: Date.UTC(2015, 9, 01), value: 2.9},
111
{x: Date.UTC(2015, 10, 01), value: 2.9},
112
{x: Date.UTC(2015, 11, 01), value: 2.9},
113
{x: Date.UTC(2016, 0, 01), value: 2.9},
114
{x: Date.UTC(2016, 1, 01), value: 2.9, valueError: "0.5%"},
115
{x: Date.UTC(2016, 2, 01), value: 2.9, valueError: "0.5%"},
116
{x: Date.UTC(2016, 3, 01), value: 2.95, valueError: "1%"},
117
{x: Date.UTC(2016, 4, 01), value: 3.0, valueError: "1%"},
118
{x: Date.UTC(2016, 5, 01), value: 3.0, valueError: "1%"},
119
{x: Date.UTC(2016, 6, 01), value: 3.05, valueError: "1.5%"},
120
{x: Date.UTC(2016, 7, 01), value: 3.1, valueError: "1.5%"},
121
{x: Date.UTC(2016, 8, 01), value: 3.1, valueError: "1.5%"},
122
{x: Date.UTC(2016, 9, 01), value: 3.1, valueError: "1.5%"},
123
{x: Date.UTC(2016, 10, 01), value: 3.1, valueError: "2%"},
124
{x: Date.UTC(2016, 11, 01), value: 3.2, valueError: "2%"},
125
{x: Date.UTC(2017, 0, 01), value: 3.25, valueError: "2%"},
126
{x: Date.UTC(2017, 1, 01), value: 3.3, valueError: "2.5%"},
127
{x: Date.UTC(2017, 2, 01), value: 3.35, valueError: "2.5%"},
128
{x: Date.UTC(2017, 3, 01), value: 3.375, valueError: "2.5%"},
129
{x: Date.UTC(2017, 4, 01), value: 3.4, valueError: "3%"},
130
{x: Date.UTC(2017, 5, 01), value: 3.425, valueError: "3.5%"},
131
{x: Date.UTC(2017, 6, 01), value: 3.45, valueError: "3.5%"},
132
{x: Date.UTC(2017, 7, 01), value: 3.475, valueError: "3.5%"},
133
{x: Date.UTC(2017, 8, 01), value: 3.5, valueError: "4%"},
134
{x: Date.UTC(2017, 9, 01), value: 3.525, valueError: "4%"},
135
{x: Date.UTC(2017, 10, 01), value: 3.55, valueError: "5%"},
136
{x: Date.UTC(2017, 11, 01), value: 3.575, valueError: "4.5%"},
137
{x: Date.UTC(2018, 0, 01), value: 3.6, valueError: "5%"}
138
]);
139
140
series.name("?rudle oil forecast and range of uncertainty");
141
142
series.tooltip().title(false).separator(false).format(function(){
143
var value = this.value.toFixed(3);
144
if (this.valueLowerError !==0)
145
value = this.value.toFixed(3) + "?" + this.valueLowerError.toFixed(3);
146
return "Date: " + new Date(this.x).toLocaleDateString("en-US", {month: "short", year: "numeric"}) + "\n" + value + " million barrels per day";
147
});
148
149
var hoverMarkers = series.hoverMarkers();
150
hoverMarkers.size(3);
151
152
chart.interactivity("byX");
153
154
var nearFuture = chart.lineMarker();
155
nearFuture.value(Date.UTC(2016, 1, 01));
156
nearFuture.layout("vertical");
157
nearFuture.scale(chart.xScale());
158
159
var future = chart.lineMarker(1);
160
future.value(Date.UTC(2017, 1, 01));
161
future.axis(chart.xAxis());
162
163
var text = chart.textMarker(0);
164
text.value(Date.UTC(2016, 1, 01));
165
text.axis(chart.xAxis());
166
text.text("Near Future");
167
text.align("top");
168
text.anchor("topLeft");
169
text.offsetX(3);
170
text.rotation(0);
171
172
var futureText = chart.textMarker(1);
173
futureText.value(Date.UTC(2017, 1, 01));
174
futureText.axis(chart.xAxis());
175
futureText.text("Future");
176
futureText.align("top");
177
futureText.anchor("topLeft");
178
futureText.offsetX(3);
179
futureText.rotation(0);
180
181
chart.legend(true);
182
183
chart.margin().right(50);
184
185
// draw chart
186
chart.container("container");
187
chart.draw();
188
});