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 scatter chart
3
var chart = anychart.scatter();
4
// The data used in this sample can be obtained from the CDN
5
// https://cdn.anychart.com/samples/scatter-charts/scatter-chart-with-axis-ranges/data.js
6
chart
7
.line()
8
.data(getObserverData()) // eslint-disable-line no-undef
9
.name('Observed')
10
.stroke('2 #64b5f6')
11
.legendItem({
12
iconStroke: 'none',
13
iconFill: '#64b5f6'
14
});
15
chart
16
.line()
17
.data(getForecastData()) // eslint-disable-line no-undef
18
.name('Forecast')
19
.stroke('2 #1976d2')
20
.legendItem({
21
iconStroke: 'none',
22
iconFill: '#1976d2'
23
});
24
25
chart.xScale(anychart.scales.dateTime());
26
27
chart
28
.xScale()
29
.minimum(Date.UTC(2015, 5, 21, 23, 0))
30
.maximum(Date.UTC(2015, 5, 27, 12, 0));
31
chart.xScale().ticks().interval(0, 0, 1);
32
33
chart.yScale().maximum(34);
34
35
chart
36
.xAxis()
37
.labels()
38
.hAlign('center')
39
.format(function () {
40
var weekdays = [
41
'Sunday',
42
'Monday',
43
'Tuesday',
44
'Wednesday',
45
'Thursday',
46
'Friday',
47
'Saturday'
48
];
49
var date = new Date(this.tickValue);
50
return (
51
weekdays[date.getUTCDay()] +
52
'\n' +
53
date.toLocaleDateString('en-US', {
54
month: 'short',
55
day: 'numeric'
56
})
57
);
58
});
59
60
chart
61
.lineMarker()
62
.value(Date.UTC(2015, 5, 22, 11, 32))
63
.layout('vertical')
64
.scale(chart.xScale())
65
.stroke({
66
color: '#212121',
67
dash: '5 3',
68
thickness: 2
69
});
70
71
chart
72
.legend()
73
.enabled(true)
74
.itemsFormatter(function (items) {
75
var date = new Date(chart.lineMarker(0).value());
76
items.unshift({
77
text:
78
'Graph Created ' +
79
date.toLocaleTimeString() +
80
' ' +
81
date.toDateString(),
82
iconType: 'line',
83
iconStroke: { color: '#212121', dash: '5 3', thickness: 2 }
84
});
85
return items;
86
});
87
88
chart.rangeMarker(0).from(15).to(21).fill('#ffe082 0.8');
89
90
chart.rangeMarker(1).from(21).to(22).fill('#ffb300 0.6');
91
92
chart.rangeMarker(2).from(22).to(26).fill('#ff6e40 0.6');
93
94
chart.rangeMarker(3).from(26).to(34).fill('#f48fb1 0.6');
95
96
chart
97
.textMarker(0)
98
.value(15)
99
.offsetX(10)
100
.text('Action: 15.0')
101
.anchor('left-bottom')
102
.align('left')
103
.fontColor('#212121');
104
105
chart
106
.textMarker(1)
107
.value(21)
108
.offsetX(10)
109
.text('Minor: 21.0')
110
.anchor('left-bottom')
111
.align('left')
112
.fontColor('#212121');
113
114
chart
115
.textMarker(2)
116
.value(22)
117
.offsetX(10)
118
.text('Moderate: 22.0')
119
.anchor('left-bottom')
120
.align('left')
121
.fontColor('#212121');
122
123
chart
124
.textMarker(3)
125
.value(26)
126
.offsetX(10)
127
.text('Major: 26.0')
128
.anchor('left-bottom')
129
.align('left')
130
.fontColor('#212121');
131
132
chart
133
.textMarker(4)
134
.value(30.7)
135
.offsetX(10)
136
.offsetY(5)
137
.text('Record: 30.7')
138
.anchor('right-bottom')
139
.align('right')
140
.fontColor('#212121');
141
142
chart.lineMarker(1).value(30.7).stroke('1.5 #212121');
143
144
var scale = anychart.scales.log();
145
scale.minimum(0.4).maximum(45);
146
147
chart.yAxis(1).scale(scale).orientation('right');
148
149
// set container id for the chart
150
chart.container('container');
151
// initiate chart drawing
152
chart.draw();
153
});