HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// create data set on our data
3
var dataSet = anychart.data.set(getData());
4
5
// map data for the first series, take x from the zero column and value from the first column of data set
6
var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
7
8
// map data for the second series, take x from the zero column and value from the second column of data set
9
var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
10
11
// create line chart
12
var chart = anychart.line();
13
14
// adding dollar symbols to yAxis labels
15
chart.yAxis().labels().format('${%Value}');
16
17
// turn on chart animation
18
chart.animation(true);
19
20
// turn on the crosshair
21
chart
22
.crosshair()
23
.enabled(true)
24
.yLabel({ enabled: false })
25
.yStroke(null)
26
.xStroke('#cecece')
27
.zIndex(99);
28
29
chart
30
.yAxis()
31
.title('The Share Price')
32
.labels({ padding: [5, 5, 0, 5] });
33
chart.xAxis().title('Month/Day');
34
35
// set chart title text settings
36
chart.title(
37
'The cost of ACME\'s shares\ncompared with their main competitor during month'
38
);
39
40
// create first series with mapped data
41
var firstSeries = chart.spline(firstSeriesData);
42
firstSeries.name('ACME Share Price');
43
firstSeries.markers().zIndex(100);
44
firstSeries.hovered().markers().enabled(true).type('circle').size(4);
45
46
// create second series with mapped data
47
var secondSeries = chart.spline(secondSeriesData);
48
secondSeries.name('The Competitor\'s Share Price');
49
secondSeries.markers().zIndex(100);
50
secondSeries.hovered().markers().enabled(true).type('circle').size(4);
51
52
// turn the legend on
53
chart.legend().enabled(true).fontSize(13).padding([0, 0, 20, 0]);
54
55
// set container id for the chart
56
chart.container('container');
57
58
// initiate chart drawing
59
chart.draw();
60
});
61
62
function getData() {
63
return [
64
['9/1', 10, 30],
65
['9/2', 12, 32],
66
['9/3', 11, 35],
67
['9/4', 15, 40],
68
['9/5', 20, 42],
69
['9/6', 22, 35],
70
['9/7', 21, 36],
71
['9/8', 25, 31],
72
['9/9', 31, 35],
73
['9/10', 32, 36],
74
['9/11', 28, 40],
75
['9/12', 29, 42],
76
['9/13', 40, 40],
77
['9/14', 41, 38],
78
['9/15', 45, 40],
79
['9/16', 50, 40],
80
['9/17', 65, 38],
81
['9/18', 45, 36],
82
['9/19', 50, 30],
83
['9/20', 51, 29],
84
['9/21', 65, 28],
85
['9/22', 60, 25],
86
['9/23', 62, 28],
87
['9/24', 65, 29],
88
['9/25', 45, 30],
89
['9/26', 55, 40],
90
['9/27', 59, 32],
91
['9/28', 52, 33],
92
['9/29', 53, 34],
93
['9/30', 40, 30],
94
['9/31', 45, 35]
95
];
96
}