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,also we can pud data directly to series
3
var dataSet = anychart.data.set([
4
['Jan', 22, 43, 75],
5
['Feb', 34, 45, 56],
6
['Mar', 16, 26, 67],
7
['Apr', 12, 86, 42],
8
['May', 41, 35, 17],
9
['Jun', 47, 31, 12],
10
['Jul', 39, 27, 9],
11
['Aug', 28, 16, 23],
12
['Sep', 21, 27, 47],
13
['Oct', 18, 31, 58],
14
['Nov', 24, 42, 69],
15
['Dec', 29, 39, 71]
16
]);
17
18
// map data for the first series,take value from first column of data set
19
var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
20
21
// map data for the second series,take value from second column of data set
22
var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
23
24
// map data for the third series, take x from the zero column and value from the third column of data set
25
var thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });
26
27
// create line chart
28
var chart = anychart.line();
29
30
// turn on chart animation
31
chart.animation(true);
32
33
// turn on the crosshair and tune it
34
chart
35
.crosshair()
36
.enabled(true)
37
.yLabel(false)
38
.xLabel(false)
39
.yStroke(null);
40
41
// set chart padding
42
chart.padding([10, 20, 5, 20]);
43
44
// set chart title text settings
45
chart.title('ACME corp. Problems During the Year');
46
47
// set yAxis title
48
chart.yAxis().title('Occurences per month');
49
50
// temp variable to store series instance
51
var series;
52
53
// setup first series
54
series = chart.line(firstSeriesData);
55
series.name('Purchase Returns').stroke('#000000').size(4);
56
series.hovered().markers(true);
57
58
// setup second series
59
series = chart.line(secondSeriesData);
60
series.name('Delivery Failure').size(4).stroke({
61
color: '#6C6C6C',
62
dash: '3 5 10 5'
63
});
64
series.hovered().markers(true);
65
66
// setup third series
67
series = chart.line(thirdSeriesData);
68
series.name('Order Cancellation').size(4).stroke({
69
color: '#C8C8C8',
70
dash: '3 5'
71
});
72
series.hovered().markers(true);
73
74
// interactivity and tooltip settings
75
chart.interactivity().hoverMode('by-x');
76
77
chart
78
.tooltip()
79
.displayMode('separated')
80
.positionMode('point')
81
.separator(false)
82
.position('right')
83
.anchor('left-bottom')
84
.offsetX(2)
85
.offsetY(5)
86
.title(false)
87
.format('{%Value} times');
88
89
// turn the legend on
90
chart.legend(true);
91
92
// set container id for the chart
93
chart.container('container');
94
// initiate chart drawing
95
chart.draw();
96
});