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
//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 seriesData_1 = dataSet.mapAs({'x': 0, 'value': 1});
20
21
//map data for the second series,take value from second column of data set
22
var seriesData_2 = 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 seriesData_3 = 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
34
chart.crosshair().enabled(true).yLabel().enabled(false);
35
chart.crosshair().enabled(true).xLabel().enabled(false);
36
chart.crosshair().enabled(true).yStroke(null);
37
38
//set container id for the chart
39
chart.container('container');
40
chart.padding([10, 20, 5, 20]);
41
42
//set yAxis title
43
chart.yAxis().title('Times happened per month');
44
45
/** We can edit series stroke by function in which context available
46
* @param color - stroke color
47
* @param style - dash lines style
48
* @return string/Object - acgraph.vector.Stroke type (string/Object)
49
*/
50
var seriesStrokeFunction = function (color, style) {
51
return {color: color, dash: style};
52
};
53
54
55
/** Helper Function to setup series
56
* @param series - stroke color
57
* @param name - stroke series name
58
*/
59
var seriesConfiguration = function (series, name) {
60
series.name(name);
61
series.tooltip().title(false);
62
series.tooltip().separator(false);
63
series.tooltip().format(function () {
64
return this.value + ' times'
65
});
66
series.hovered().markers().enabled(true).size(4);
67
series.tooltip().position('right').anchor('left-bottom').offsetX(2).offsetY(5);
68
};
69
70
//temp variable to store series instance
71
var series;
72
73
//we can use local variables to change series settings
74
series = chart.line(seriesData_1);
75
series.stroke('#000000');
76
seriesConfiguration(series, 'Purchase Returns');
77
78
79
//or just use chaining calls
80
series = chart.line(seriesData_2);
81
series.stroke(seriesStrokeFunction('#6C6C6C', '3 5 10 5'));
82
seriesConfiguration(series, 'Delivery Failure');
83
84
//or access series by index from chart
85
series = chart.line(seriesData_3);
86
series.stroke(seriesStrokeFunction('#C8C8C8', '3 5'));
87
seriesConfiguration(series, 'Order Cancellation');
88
89
chart.interactivity().hoverMode('by-x');
90
chart.tooltip().displayMode('separated');
91
chart.tooltip().positionMode('point');
92
//turn the legend on
93
chart.legend().enabled(true).padding([0, 0, 10, 0]);
94
95
//initiate chart drawing
96
chart.draw();
97
});