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
// The data used in this sample can be obtained from the CDN
3
// https://cdn.anychart.com/samples/sparkline-charts/column-chart/data.json
4
anychart.data.loadJsonFile(
5
'https://cdn.anychart.com/samples/sparkline-charts/column-chart/data.json',
6
function (data) {
7
// set of colors and fonts used in this demo
8
var fontFamilyText = '\'Verdana\', Helvetica, Arial, sans-serif';
9
var headerFontColor = '#545f69';
10
var borderColor = '#CECECE';
11
12
// create table for sparkline charts layout
13
var table = anychart.standalones.table();
14
// set table size settings
15
table.bounds('5%', '20px', '90%', '90%');
16
17
// set table contents (sparkline charts and text)
18
table.contents([
19
[
20
'Region',
21
'Actual Sales (mn)',
22
null,
23
null,
24
'% to\nGoal',
25
'12 Month',
26
null,
27
'Gross\nMargin',
28
'Profit Trend\n12 Month'
29
],
30
[
31
'Alabama',
32
'$4,916',
33
createLine(data.alabama, 'actualSales'),
34
null,
35
'107%',
36
createColumn(data.alabama, 'toGoal'),
37
null,
38
'$1,172',
39
createColumn(data.alabama, 'profitTrend')
40
],
41
[
42
'Alaska',
43
'$3,916',
44
createLine(data.alaska, 'actualSales'),
45
null,
46
'65%',
47
createColumn(data.alaska, 'toGoal'),
48
null,
49
'-$791',
50
createColumn(data.alaska, 'profitTrend')
51
],
52
[
53
'Arizona',
54
'$4,916',
55
createLine(data.arizona, 'actualSales'),
56
null,
57
'103%',
58
createColumn(data.arizona, 'toGoal'),
59
null,
60
'$1,010',
61
createColumn(data.arizona, 'profitTrend')
62
],
63
[
64
'Idaho',
65
'$5,916',
66
createLine(data.idaho, 'actualSales'),
67
null,
68
'101%',
69
createColumn(data.idaho, 'toGoal'),
70
null,
71
'$1,030',
72
createColumn(data.idaho, 'profitTrend')
73
],
74
[
75
'Illinois',
76
'$4,916',
77
createLine(data.illinois, 'actualSales'),
78
null,
79
'92%',
80
createColumn(data.illinois, 'toGoal'),
81
null,
82
'-$90',
83
createColumn(data.illinois, 'profitTrend')
84
],
85
[
86
'Indiana',
87
'$5,916',
88
createLine(data.indiana, 'actualSales'),
89
null,
90
'89%',
91
createColumn(data.indiana, 'toGoal'),
92
null,
93
'-$139',
94
createColumn(data.indiana, 'profitTrend')
95
],
96
[
97
'Ohio',
98
'$5,916',
99
createLine(data.ohio, 'actualSales'),
100
null,
101
'113%',
102
createColumn(data.ohio, 'toGoal'),
103
null,
104
'$1,196',
105
createColumn(data.ohio, 'profitTrend')
106
],
107
[
108
'Oklahoma',
109
'$4,916',
110
createLine(data.oklahoma, 'actualSales'),
111
null,
112
'81%',
113
createColumn(data.oklahoma, 'toGoal'),
114
null,
115
'-$127',
116
createColumn(data.oklahoma, 'profitTrend')
117
],
118
[
119
'Oregon',
120
'$6,916',
121
createLine(data.oregon, 'actualSales'),
122
null,
123
'92%',
124
createColumn(data.oregon, 'toGoal'),
125
null,
126
'-$16',
127
createColumn(data.oregon, 'profitTrend')
128
],
129
[
130
'Vermont',
131
'$4,916',
132
createLine(data.vermont, 'actualSales'),
133
null,
134
'118%',
135
createColumn(data.vermont, 'toGoal'),
136
null,
137
'$1,240',
138
createColumn(data.vermont, 'profitTrend')
139
],
140
[
141
'Virginia',
142
'$7,916',
143
createLine(data.virginia, 'actualSales'),
144
null,
145
'192%',
146
createColumn(data.virginia, 'toGoal'),
147
null,
148
'$4,172',
149
createColumn(data.virginia, 'profitTrend')
150
],
151
[
152
'Washington',
153
'$5,916',
154
createLine(data.washington, 'actualSales'),
155
null,
156
'69%',
157
createColumn(data.washington, 'toGoal'),
158
null,
159
'-$390',
160
createColumn(data.washington, 'profitTrend')
161
]
162
]);
163
164
// span [0,1] and [0,2] cell
165
table.getCell(0, 1).colSpan(2);
166
// disable borders for all cells in the table
167
table.cellBorder(null);
168
// set dashed bottom border for all cells in the table
169
table.cellBorder().bottom({ color: borderColor, dash: '1 1' });
170
171
// set default text settings for the table
172
table
173
.hAlign('center')
174
.vAlign('middle')
175
.fontSize('12px')
176
.fontFamily(fontFamilyText);
177
178
// set fixed height for the first row
179
table.getRow(0).height(40).fontColor(headerFontColor);
180
181
// set fixed width for some of the tables columns
182
table.getCol(0).width(90).hAlign('left');
183
table.getCol(1).width(65);
184
table.getCol(3).width(20).cellBorder().bottom('none');
185
table.getCol(4).width(65);
186
table.getCol(6).width(20).cellBorder().bottom('none');
187
table.getCol(7).width(65);
188
189
// set container id for the table
190
table.container('container');
191
// draw the table and all elements it contains
192
// (you don't need to call the draw method for internal tables and charts)
193
table.draw();
194
}
195
);
196
});
197
198
/**
199
* Helper function, creates sparkline chart with Line type using anychart.sparkline method,
200
* sets passed data and visual preference.
201
* @param {Object.<string, Array>} data Sparkline data.
202
* @param {string} field Data field
203
* @return {anychart.charts.Sparkline} New sparkline chart with passed data.
204
*/
205
function createLine(data, field) {
206
var sparkline = anychart.sparkline(data[field]);
207
sparkline.seriesType('line');
208
sparkline.height('100%');
209
sparkline.margin().top('5%');
210
sparkline.margin().bottom('5%');
211
sparkline.padding(0);
212
return sparkline;
213
}
214
215
/**
216
* Helper function, creates sparkline chart with Bar type using anychart.sparkline method,
217
* sets passed data and visual preference.
218
* @param {Object.<string, Array>} data Sparkline data.
219
* @param {string} field Data field
220
* @return {anychart.charts.Sparkline} New sparkline chart with passed data.
221
*/
222
function createColumn(data, field) {
223
var sparkline = anychart.sparkline(data[field]);
224
sparkline.seriesType('column');
225
sparkline.height('100%');
226
sparkline.margin().top('5%');
227
sparkline.margin().bottom('5%');
228
sparkline.padding(0);
229
return sparkline;
230
}