forked from typpo/quickchart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
407 lines (385 loc) · 13.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chart Images from URL | QuickChart</title>
{% include "meta.html" %}
<style>
html, body {
margin: 0;
}
body {
font-family: 'Proxima Nova Soft','Helvetica Neue',Arial,Helvetica,sans-serif;
}
a, a:visited {
color: darkblue;
}
.centered {
text-align: center;
}
.header {
background-color: linen;
padding: 1em;
margin-bottom: 1em;
}
.container {
margin: 0 auto;
max-width: 1024px;
padding: 0 1em;
}
.hero {
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.col {
flex: 1;
}
.arrowcol {
flex: 0.2;
color: rgba(72, 56, 74, 0.2);
font-size: 4em;
}
.arrowcol:before {
content: "➜";
}
.sandbox-input {
width: 98%;
height: 17em;
-webkit-box-shadow: 0 0 10px rgba(255,0,0,0.2);
-moz-box-shadow: 0 0 10px rgba(255,0,0,0.2);
}
.sandbox-tag {
font-size: 10px;
margin-bottom: 1em;
}
.panel {
padding: 1em;
margin-bottom: 2em;
-webkit-box-shadow: 0 0 10px rgba(0,0,0,0.2);
-moz-box-shadow: 0 0 10px rgba(0,0,0,0.2);
}
.hl {
background-color: #E9FF32;
}
.img-example {
max-width: 100%;
}
pre.json {
background-color: #eee;
overflow: scroll;
}
code {
overflow-x: scroll;
max-width: 100%;
}
footer {
color: #aaa;
background-color: #eee;
}
.footer-content {
padding: 1em;
}
.mobile-only {
display: none;
}
.desktop-only {
display: block;
}
@media (max-width: 400px) {
.container {
padding: 0 0.5em;
}
.hero {
display: block;
}
.arrowcol {
text-align: center;
font-size: 3em;
}
.arrowcol:before {
content: "⇣";
}
.mobile-only {
display: block;
}
.desktop-only {
display: none;
}
}
</style>
</head>
<body>
<div class="header centered">
<h1>Generate a Chart Image from URL</h1>
<p>
<!--
Fast & Reliable · One URL · Easy to Save · Easy to Embed
-->
<strong>Create static charts for embedding in email, SMS, reports, and more.</strong>
</p>
<p>
<a href="#build-from-url">How It Works</a> · <a href="#customize">Customize Your Chart</a> · <a href="#chart-types">Chart Types</a> · <a href="#about">More Info</a>
</p>
</div>
<div class="container">
<div class="hero">
<div class="col">
<h2>
Create a chart using an HTML image tag
</h2>
<p>
<code>
<img src="https://quickchart.io/chart?c=<span class="hl">{type:'bar',data:{labels:['January','February','March','April', 'May'], datasets:[{label:'Dogs',data:[50,60,70,180,190]},{label:'Cats',data:[100,200,300,400,500]}]}}"></span>
</code>
</p>
</div>
<div class="arrowcol"></div>
<div class="col">
<img class="img-example" src="/chart?c={type:'bar',data:{labels:['January\n','February','March','April', 'May'],datasets:[{label:'Dogs',data:[50,60,70,180,190]},{label:'Cats',data:[100,200,300,400,500]}]}}"/>
</div>
</div>
<p>
This service is a replacement for the <a href="https://developers.google.com/chart/image/">Google Image Charts API</a>, which is scheduled to turn off on March 14, 2019.
</p>
<hr/>
<h2 id="build-from-url">How It Works</h2>
<p>
Chart images are defined by their URLs. Each URL contains a JSON object that includes all the data and display options. These options follow the popular open-source graphing library Chart.js. Use the <a href="https://www.chartjs.org/docs/latest/charts/">documentation</a> to define your chart.
</p>
<p>
Once you've written your JSON, render it as an image with <code class="hl"><img src="https://quickchart.io/chart?c=[[insert json here]]"></code>. Try the realtime editor below:
</p>
<div class="hero panel">
<div class="col">
<textarea id="sandbox-input" class="sandbox-input">// Edit me!
{
type: 'bar',
data: {
labels: ['January', 'February', 'March', 'April', 'May'],
datasets: [{
label: 'Dogs',
data: [ 50, 60, 70, 180, 190 ]
}, {
label: 'Cats',
data: [ 100, 200, 300, 400, 500 ]
}]
}
}</textarea>
</div>
<div class="arrowcol"></div>
<div class="col">
<div id="sandbox-tag" class="sandbox-tag"></div>
<img class="img-example" id="sandbox-img"/>
</div>
</div>
<h2 id="customize">Customize Your Chart</h2>
<p>
We can get very creative. The example below uses custom background colors, title, legend, stacked bars, and data labels:
</p>
<div class="hero">
<div class="col">
<pre class="json">
{
type: 'bar',
data: {
labels: ['January', 'February', 'March', 'April', 'May'],
datasets: [{
label: 'Dogs',
backgroundColor: 'chartreuse',
data: [ 50, 60, 70, 180, 190 ]
}, {
label: 'Cats',
backgroundColor: 'gold',
data: [ 100, 200, 300, 400, 500 ]
}]
},
options: {
title: {
display: true,
text: 'Total Revenue (billions)',
fontColor: 'hotpink',
fontSize: 32,
},
legend: {
position: 'bottom',
},
scales: {
xAxes: [{stacked: true}],
yAxes: [{stacked: true}],
},
plugins: {
datalabels: {
display: true,
font: {
style: 'bold',
},
},
},
},
}
</pre>
</div>
<div class="arrowcol"></div>
<div class="col">
<img class="img-example" src="/chart?c=
{
type: 'bar',
data: {
labels: ['January', 'February', 'March', 'April', 'May'],
datasets: [{
label: 'Dogs',
backgroundColor: 'chartreuse',
data: [ 50, 60, 70, 180, 190 ]
}, {
label: 'Cats',
backgroundColor: 'gold',
data: [ 100, 200, 300, 400, 500 ]
}]
},
options: {
title: {
display: true,
text: 'Total Revenue (billions)',
fontColor: 'hotpink',
fontSize: 32,
},
legend: {
position: 'bottom',
},
scales: {
xAxes: [{stacked: true}],
yAxes: [{stacked: true}],
},
plugins: {
datalabels: {
display: true,
font: {
style: 'bold',
},
},
},
},
}
"/>
</div>
</div>
<p>
You can use any static customization option available in Chart.js. The best place to learn the extent of customization options is through the <a href="https://www.chartjs.org/docs/latest/configuration/">documentation</a>.
</p>
<p>
A couple things to remember when customizing your chart:
<ul>
<li>Interactivity and animations are not supported (this service produces static images)</li>
<li><em>We recommend that you <a href="https://meyerweb.com/eric/tools/dencoder/">URL-encode</a> the entire JSON block.</em> If not URL-encoded, you must escape all hex characters, e.g. <code>#ff0000</code> → <code>%23ff0000</code>, or just use the <code>rgb(255, 0, 0)</code> equivalent</li>
</ul>
</p>
<p>
We also provide these additional options as query parameters:
<ul>
<li><code><strong>&width</strong>=500</code>: Set the width of the image. Abbreviated as "w"</li>
<li><code><strong>&height</strong>=300</code>: Set the height of the image. Abbreviated as "h"</li>
</ul>
Combine these parameters in your query string. For example: <code>/chart?width=500&height=300&c={...}</code>
</p>
<hr/>
<h2 id="chart-types">Chart Types</h2>
<p>
Customization can be very simple. By changing <code class="hl">type: bar</code> to <code class="hl">type: line</code>, for example, we can instantly produce an equivalent line graph:
</p>
<div class="hero panel">
<div class="col">
<h3>Bar Graph</h3>
<code>
<img src="https://quickchart.io/chart?c={<span class="hl">type:'bar'</span>,data:{labels:['January','February','March','April', 'May'], datasets:[{label:'Dogs',data:[50,60,70,180,190]},{label:'Cats',data:[100,200,300,400,500]}]}}">
</code>
</div>
<div class="arrowcol"></div>
<div class="col">
<img class="img-example" src="/chart?c={type:'bar',data:{labels:['January','February','March','April', 'May'],datasets:[{label:'Dogs',data:[50,60,70,180,190]},{label:'Cats',data:[100,200,300,400,500]}]}}"/>
</div>
</div>
<div class="hero panel">
<div class="col">
<h3>Line Graph</h3>
<code>
<img src="https://quickchart.io/chart?c={<span class="hl">type:'line'</span>,data:{labels:['January','February','March','April', 'May'], datasets:[{label:'Dogs',data:[50,60,70,180,190]},{label:'Cats',data:[100,200,300,400,500]}]}}">
</code>
</div>
<div class="arrowcol"></div>
<div class="col">
<img class="img-example" src="/chart?c={type:'line',data:{labels:['January','February','March','April', 'May'],datasets:[{label:'Dogs',data:[50,60,70,180,190]},{label:'Cats',data:[100,200,300,400,500]}]}}"/>
</div>
</div>
<p>
There are many other chart types as well:
</p>
<div class="hero panel">
<div class="col">
<h3>Radar Chart</h3>
<code>
<img src="https://quickchart.io/chart?c={<span class="hl">type:'radar'</span>,data:{labels:['January','February','March','April', 'May'], datasets:[{label:'Dogs',data:[50,60,70,180,190]},{label:'Cats',data:[100,200,300,400,500]}]}}">
</code>
</div>
<div class="arrowcol"></div>
<div class="col">
<img class="img-example" src="/chart?c={type:'radar',data:{labels:['January','February','March','April', 'May'],datasets:[{label:'Dogs',data:[50,60,70,180,190]},{label:'Cats',data:[100,200,300,400,500]}]}}"/>
</div>
</div>
<div class="hero panel">
<div class="col">
<h3>Pie Charts</h3>
<code>
<img src="https://quickchart.io/chart?c={<span class="hl">type:'pie'</span>,data:{labels:['January','February','March','April', 'May'], datasets:[{data:[50,60,70,180,190]}]}}">
</code>
</div>
<div class="arrowcol"></div>
<div class="col">
<img class="img-example" src="/chart?c={type:'pie',data:{labels:['January','February','March','April', 'May'],datasets:[{data:[50,60,70,180,190]}]}}"/>
</div>
</div>
<div class="hero panel">
<div class="col">
<h3>Doughnut Charts</h3>
<code>
<img src="https://quickchart.io/chart?c={<span class="hl">type:'doughnut'</span>,data:{labels:['January','February','March','April', 'May'], datasets:[{data:[50,60,70,180,190]}]}}">
</code>
</div>
<div class="arrowcol"></div>
<div class="col">
<img class="img-example" src="/chart?c={type:'doughnut',data:{labels:['January','February','March','April', 'May'],datasets:[{data:[50,60,70,180,190]}]}}"/>
</div>
</div>
<h2 id="about">About QuickChart.io</h2>
<p>
QuickChart is a free service built and maintained by Ian Webster. It was built in response to the Google Image Charts shutdown and is funded entirely by its sponsors: <a href="https://arthena.com/">Arthena</a>, <a href="https://skepticalinvestments.biz/">Skeptical Investments</a>, and <a href="https://www.zenysis.com/">Zenysis</a>. You may use images produced by this website for any purpose.
</p>
<p>
QuickChart is <a href="https://github.com/typpo/quickchart">open source</a>, dual licensed under the GNU GPLv3 and a commercial license. This means that QuickChart is never going away: anyone can host this service with minimal resource requirements. If you would like to modify the QuickChart source code for commercial use, please <a href="mailto:ian@alioth.io">contact us</a> for a license.
</p>
</div>
<footer>
<div class="footer-content">
© Ian Webster 2019
</div>
</footer>
<script>
var input = document.getElementById('sandbox-input');
var img = document.getElementById('sandbox-img');
var tag = document.getElementById('sandbox-tag');
function updateImage() {
img.src = '/chart?c=' + encodeURIComponent(input.value);
var lines = input.value.split('\n').filter(function(line) {
return line.slice(0, 2) !== '//';
});
tag.innerHTML = '<img src="https://quickchart.io/chart?c=' + lines.join('') + '">';
}
input.onkeyup = updateImage;
updateImage();
</script>
{% include "tracking.html" %}
</body>
</html>