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
// chart type
4
var chart = anychart.line();
5
6
// set chart title and adjust it
7
var title = chart.title();
8
title.enabled(true);
9
title.text("Profitability Growth\n(in % to the previous year)");
10
title.hAlign("center");
11
title.fontColor("white");
12
13
// set background color
14
var background = chart.background();
15
background.fill({
16
// set colors position
17
keys: ["#406181", "#6DA5DB"],
18
// set angle of colors drawing
19
angle: 90
20
});
21
22
// data
23
var data = anychart.data.set([
24
["Jan", 34],
25
["Feb", 44],
26
["Mar", 48],
27
["Apr", 54],
28
["May", 60],
29
["Jun", 70],
30
["Jul", 58],
31
["Aug", 62],
32
["Sep", 54],
33
["Oct", 45],
34
["Nov", 39],
35
["Dec", 23]
36
]);
37
38
// set data into series
39
var series = chart.line(data);
40
41
// set chart stroke color, thickness dash
42
series.stroke({color: "#BBDA00", dash: "4 3", thickness: 3});
43
series.hoverStroke({color: "#BBDA00", dash: "4 3", thickness: 3});
44
series.name("dashed stroke");
45
46
// adjust markers of a series
47
var markers = series.markers();
48
markers.enabled(true);
49
markers.fill("#BBDA00");
50
markers.stroke("2 white");
51
var hoverMarkers = series.hoverMarkers();
52
hoverMarkers.fill("darkred");
53
hoverMarkers.stroke("2 white");
54
55
// adjust tooltip
56
var tooltip = series.tooltip();
57
tooltip.format(function(){
58
return this.x + ", " + this.value + "%";
59
});
60
tooltip.fontColor("white");
61
62
var tooltipBackground = series.tooltip().background();
63
tooltipBackground.fill("#406181");
64
tooltipBackground.stroke("white");
65
tooltipBackground.cornerType("round");
66
tooltipBackground.corners(4);
67
68
69
// adjust y axis
70
var yAxis = chart.yAxis();
71
yAxis.ticks(null);
72
yAxis.minorTicks(null);
73
yAxis.stroke("white");
74
var yLabels = chart.yAxis().labels();
75
yLabels.fontColor("white");
76
yLabels.fontWeight(900);
77
yLabels.format(function() {
78
return this.value + " %";
79
});
80
81
// set additional y axis hide dashed right stroke of a grid
82
var yAxis1 = chart.yAxis(1);
83
yAxis1.ticks(null);
84
yAxis1.stroke("white");
85
yAxis1.labels(null);
86
yAxis1.orientation("right");
87
88
// adjust x axis
89
var xAxis = chart.xAxis();
90
xAxis.stroke("white");
91
var xLabels = chart.xAxis().labels();
92
xLabels.fontColor("white");
93
xLabels.fontWeight(900);
94
xLabels.height(30);
95
xLabels.vAlign("middle");
96
97
98
// adjust grid
99
var grid = chart.grid();
100
grid.enabled(true);
101
grid.stroke({color: "white", dash: "3 5"});
102
grid.evenFill(null);
103
grid.oddFill("black 0.1");
104
grid.layout("vertical");
105
var grid1 = chart.grid(1);
106
grid1.enabled(true);
107
grid1.stroke("white");
108
grid1.layout("horizontal");
109
110
// adjust y scale
111
var yScale = chart.yScale();
112
yScale.maximum(100);
113
var yTicks = chart.yScale().ticks();
114
yTicks.interval(20);
115
116
// draw
117
chart.container("container");
118
chart.draw();
119
});