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 stage
3
var stage = anychart.graphics.create('container');
4
5
// The data used in this sample can be obtained from the CDN
6
// https://cdn.anychart.com/anydata/bitcoin/result.json
7
anychart.data.loadJsonFile(
8
'https://cdn.anychart.com/anydata/bitcoin/result.json',
9
function (data) {
10
// create column chart
11
var chart = anychart.column();
12
// set chart padding
13
chart
14
.padding([20, 0, 15, 20])
15
// set chart bounds
16
.bounds(0, 0, '70%', '100%');
17
18
// set chart title text settings
19
var chartTitle = chart.title();
20
chartTitle
21
.enabled(true)
22
.fontSize(15)
23
.text(
24
'Bitcoin - Capitalization vs Market Share<br><span style="font-size: 12px; color: #999">(last 12 months)</span>'
25
)
26
.useHtml(true);
27
chartTitle.padding().bottom(15);
28
29
// create data set on our data
30
var dataSet = anychart.data.set(data.lineChartData);
31
32
// create ordinal scale
33
var linearScale = anychart.scales.linear();
34
linearScale.minimum(0);
35
36
// create line series
37
var lineSeries = chart.line(
38
dataSet.mapAs({ value: 'capitalization' })
39
);
40
// set series name
41
lineSeries.name('Capitalization');
42
lineSeries.markers(true).stroke('1.5 #60727b');
43
// set line series labels settings
44
lineSeries
45
.labels()
46
.format(
47
'${%Value}{scale:(1)(1000)(1000)(1000)|( d)( th)( M)( B)}'
48
);
49
// set line series tooltip settings
50
lineSeries
51
.tooltip()
52
.format(
53
'Capitalization: ${%Value}{scale:(1)(1000)(1000)(1000)|( d)( th)( M)( B)}'
54
);
55
56
// create column series
57
var columnSeries = chart.column(
58
dataSet.mapAs({ value: 'dominance' })
59
);
60
// set series name
61
columnSeries
62
.name('Market Share')
63
.fill('#7bc0f7')
64
// set y-scale
65
.yScale(linearScale);
66
// set column series tooltip settings
67
columnSeries.tooltip().format('Market Share: {%Value}%');
68
69
// set settings for the first y-axis
70
var firstYAxis = chart.yAxis(0);
71
firstYAxis.title('Capitalization');
72
firstYAxis
73
.labels()
74
.format(
75
'${%Value}{scale:(1)(1000)(1000)(1000)|( d)( th)( M)( B)}'
76
);
77
78
// set settings for the second y-axis
79
var secondYAxis = chart.yAxis(1);
80
secondYAxis
81
.scale(linearScale)
82
.orientation('right')
83
.title('Market Share');
84
secondYAxis.labels().format('{%Value}%');
85
86
// set chart tooltip settings
87
chart
88
.tooltip()
89
.displayMode('union')
90
// format title tooltip
91
.titleFormat(function () {
92
return this.x + ' ' + this.name.split('.')[0];
93
});
94
95
// turn on legend
96
chart.legend(true);
97
98
// set hover mode
99
chart.interactivity().hoverMode('by-x');
100
101
// set container for the chart
102
chart.container(stage);
103
104
// initiate chart drawing
105
chart.draw();
106
107
// set output date format
108
anychart.format.outputDateFormat('dd MMM yyyy');
109
110
// create pie chart
111
var pie = anychart.pie(data.pieData);
112
// set pie padding
113
pie
114
.padding([20, 10, 20, 10])
115
// set pie bounds
116
.bounds('70%', 0, '30%', '100%')
117
// changes palette for this sample
118
.palette([
119
'#64b5f6',
120
'#1976d2',
121
'#ef6c00',
122
'#ffd54f',
123
'#455a64',
124
'#dd2c00',
125
'#96a6a6',
126
'#00838f',
127
'#00bfa5',
128
'#ffa000'
129
])
130
// create empty area in pie chart
131
.innerRadius('30%');
132
133
// set chart title text settings
134
var pieTitle = pie.title();
135
pieTitle
136
.enabled(true)
137
.fontSize(15)
138
.useHtml(true)
139
.text(
140
'Cryptocurrency Market Share<br><span style="font-size: 12px; color: #999">(' +
141
anychart.format.date(data.parseDate) +
142
')</span>'
143
);
144
pieTitle.padding().bottom(15);
145
146
// set legend layout
147
pie
148
.legend()
149
.itemsLayout('horizontal-expandable')
150
.position('bottom-center');
151
152
// set pie tooltip settings
153
pie.tooltip().format('Market Share: {%PercentValue}%');
154
155
// set container for the chart
156
pie.container(stage);
157
158
// initiate chart drawing
159
pie.draw();
160
}
161
);
162
});