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
// JSON data
4
var json = {
5
// chart settings
6
"chart": {
7
// chart type
8
"type": "column",
9
// set chart title
10
"title": "My data",
11
// series settings
12
"series": [{
13
// first series data
14
"data": [
15
{x: "07-10-2020", value: -50, label: "In"},
16
{x: "07-10-2020", value: -50, label: "Ma"},
17
{x: "14-10-2020", value: -50, label: "In,"},
18
{x: "14-10-2020", value: -50, label: "Ma"},
19
{x: "19-10-2020", value: -50, label: "In"},
20
{x: "19-10-2020", value: -50, label: "Ma"},
21
{x: "23-10-2020", value: -50, label: "In"},
22
{x: "23-10-2020", value: -50, label: "Ma"},
23
{x: "29-10-2020", value: 50, label: "In"},
24
{x: "29-10-2020", value: -50, label: "Ma"},
25
{x: "04-11-2020", value: 50, label: "In"},
26
{x: "04-11-2020", value: -50, label: "M"},
27
{x: "13-11-2020", value: 50, label: "In"},
28
{x: "13-11-2020", value: -50, label: "Ma"},
29
{x: "26-11-2020", value: 50, label: "In"},
30
{x: "26-11-2020", value: 50, label: "Ma"}
31
]
32
},
33
//second
34
{"data": [{x: "26-03-2019", value: 50, label: "Ap"}]},
35
//third
36
{"data": [
37
{x: "02-07-2019", value: 50, label: "Ingr."},
38
{x: "11-07-2019", value: 50, label: "Ingr."},
39
{x: "19-07-2019", value: 50, label: "Ingr."},
40
{x: "30-07-2019", value: 50, label: "Ingr."},
41
{x: "06-08-2019", value: 50, label: "Ingr."},
42
{x: "20-08-2019", value: -50, label: "Ingr."},
43
{x: "27-08-2019", value: 50, label: "Ingr."},
44
{x: "03-09-2019", value: 50, label: "Ingr."},
45
{x: "10-09-2019", value: 50, label: "Ingr."}
46
]}
47
],
48
49
// chart container
50
"container": "container"
51
}
52
};
53
54
// get JSON data
55
var chart = anychart.fromJson(json);
56
57
/**
58
var dateScale = anychart.scales.dateTime();
59
chart.xScale(dateScale);
60
61
chart.xAxis().labels().format(function(value){
62
var date = new Date(value["tickValue"]);
63
var options = {
64
year: "numeric",
65
month: "numeric",
66
day:"numeric"
67
};
68
return date.toLocaleDateString("it-it", options);
69
});
70
**/
71
72
73
chart.xAxis().orientation("bottom")
74
.title("Date")
75
76
77
chart.xAxis().labels().rotation(-90);
78
79
80
81
//y
82
chart.yAxis().title("%");
83
chart.yAxis(0).labels().enabled(true);
84
85
//scala
86
chart.yScale().ticks().allowFractional(false);
87
chart.yScale().ticks().set(["50","0","-50"]);
88
89
90
// draw chart
91
chart.draw();
92
});