Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
js_charts
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Gordon Diggs
June 14, 2013
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
js_charts
Gordon Diggs
June 14, 2013
More Decks by Gordon Diggs
See All by Gordon Diggs
John Coltrane: Lessons in Leadership
gordondiggs
2
310
The Customer Gap
gordondiggs
1
120
Picking Records with JavaScript and a Button
gordondiggs
0
88
Kafka Partitioning Algorithm
gordondiggs
0
150
Supbutton
gordondiggs
0
91
Rayons
gordondiggs
0
97
Sous Vide
gordondiggs
0
120
Dev Events & Internal Tools at Paperless Post
gordondiggs
0
130
The Joys and Pains of Working With an Old Codebase
gordondiggs
0
160
Featured
See All Featured
How GitHub (no longer) Works
holman
316
150k
Balancing Empowerment & Direction
lara
6
1.2k
New Earth Scene 8
popppiees
3
2.3k
4 Signs Your Business is Dying
shpigford
187
22k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
170
Building an army of robots
kneath
306
46k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Unsuck your backbone
ammeep
672
58k
Embracing the Ebb and Flow
colly
88
5.1k
Transcript
Javascript Chart Libraries Gordon Diggs PP Dev Lightning Talks 130614
Friday, June 14, 13
A little history Friday, June 14, 13
My considerations • Lots of data • Need labels to
be relevant/understandable • Raw numbers more significant than comparisons Friday, June 14, 13
d3.js / rickshaw probably amazing. Friday, June 14, 13
A chronological look at the ones I’ve used Friday, June
14, 13
Google Charts API • Not actually javascript • Static images
• Pass all the data in the URL • Will do automatic gradient • Deprecated Friday, June 14, 13
Google Charts API • http://chart.apis.google.com/chart? cht=p&chd=s:world5&chs=200x125&chl=A |B|C|D|E|Fe Friday, June 14,
13
Google Charts API Friday, June 14, 13
Google Charts API (js) • Great interactivity, can bind events
• Auto-coloring • Pain to set up • Data format kind of weird • Not really open source Friday, June 14, 13
var drawChart = function(elem) {
var options = { backgroundColor: { fill: '#2F2F2F', stroke: '#2F2F2F' }, pieSliceBorderColor: '#2F2F2F', pieSliceText: 'label', pieSliceTextStyle: { color: 'black', fontSize: '12' }, legend: {position: 'none'}, chartArea: {width: '800', height: '500'} }; $.getJSON('/occurrences', { field: $(elem).attr('data-‐field') }, function(response) { console.log("response for field:", $(elem).attr('data-‐field'), response); var data = google.visualization.arrayToDataTable(response.occurrence); var chart = new google.visualization.PieChart(elem) chart.draw(data, options); // add select listener to jump to search results from pie charts google.visualization.events.addListener(chart, 'select', function() { var selected = chart.getSelection()//, label = data.getFormattedValue(selected[0].row, 0); if(confirm("Go to results for '" + label + "'?")) { window.location.href = '/?search=' + encodeURIComponent(label); } }); }); }; $('.chart').each(function(i) { drawChart(this); }); Friday, June 14, 13
Google Charts API (js) Friday, June 14, 13
Google Charts API (js) • https://developers.google.com/chart/ Friday, June 14, 13
Chart.js • Canvas • Good initialization • Nice animation •
Limited Interactivity • No labels Friday, June 14, 13
$('.chart').each(function(i) {
var $elem = $(this), ctx = $elem.find('canvas')[0].getContext("2d"); $.getJSON('/stats', { field: $elem.attr('data-‐field') }, function(response) { var data = [], colors = colorGradient('224466', '6699bb', response.length); $.each(response, function(i, datum) { datum.color = colors[i % colors.length]; data[i] = datum; }); new Chart(ctx).Pie(data, { segmentStrokeColor: '#2F2F2F', segmentStrokeWidth: 1, animation: false }); }); }); Friday, June 14, 13
Chart.js Friday, June 14, 13
Chart.js • http://www.chartjs.org Friday, June 14, 13
Chartkick • One line of ruby • Takes ruby data
structures • Interactivity and labels Friday, June 14, 13
= pie_chart Item.group("artist").count Friday, June 14, 13
Chartkick Friday, June 14, 13
Chartkick • http://ankane.github.io/chartkick/ Friday, June 14, 13
BONUS: jqcloud • Easy way to make word clouds with
jQuery Friday, June 14, 13
$.each($('.frequency'), function(i, freq) { $.getJSON('/items/words_for_field?field='+$(freq).data('field'), function(response)
{ $(freq).jQCloud(response); }); }); Friday, June 14, 13
jqcloud Friday, June 14, 13
jqcloud • https://github.com/lucaong/jQCloud Friday, June 14, 13
Thanks! Friday, June 14, 13