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
// data
4
var data = [
5
{x: Date.UTC(2007, 7, 28), open:511.53, high:514.98, low:505.79, close:506.40},
6
{x: Date.UTC(2007, 7, 29), open:507.84, high:513.30, low:507.23, close:512.88},
7
{x: Date.UTC(2007, 7, 30), open:512.36, high:515.40, low:510.58, close:511.40},
8
{x: Date.UTC(2007, 7, 31), open:513.10, high:516.50, low:511.47, close:515.25},
9
{x: Date.UTC(2007, 8, 4), open:515.02, high:528.00, low:514.62, close:525.15}
10
];
11
// chart type
12
var chart = anychart.financial();
13
14
// set axes title
15
var xAxis = chart.xAxis();
16
xAxis.title("Day");
17
xAxis.staggerLines(1);
18
var yAxis = chart.yAxis();
19
yAxis.title("Price");
20
21
// chart title
22
chart.title("Open High Low Close (OHLC) Chart");
23
24
// adjust x scale type
25
var scale = chart.xScale();
26
scale.minimum(Date.UTC(2007, 7, 27));
27
scale.maximum(Date.UTC(2007, 8, 5));
28
var xTicks = scale.ticks();
29
xTicks.interval(0,0,1);
30
31
// set data and define chart type
32
var series = chart.ohlc(data);
33
34
// set x axis labels width for the better outlook
35
var xLabels = chart.xAxis().labels();
36
xLabels.format(function(value){
37
var date = new Date(value["tickValue"]);
38
var options = {
39
day: "numeric",
40
month: "short"
41
};
42
return date.toLocaleDateString("en-US", options);
43
});
44
45
// change the selected regions color to the dark violet from the default
46
series.risingStroke("#5400BA");
47
series.hoverRisingStroke("#C3A6E7");
48
49
// set interactivity mode
50
var interactivity = chart.interactivity();
51
interactivity.hoverMode("byX");
52
53
// set container
54
chart.container("container");
55
56
// limit width of each point in series
57
series.pointWidth(chart.container().width()/15);
58
59
//draw chart
60
chart.draw();
61
62
// enabling the selection
63
series.select([1,2]);
64
});