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
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
89
Kafka Partitioning Algorithm
gordondiggs
0
160
Supbutton
gordondiggs
0
96
Rayons
gordondiggs
0
100
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
Git: the NoSQL Database
bkeepers
PRO
432
67k
Music & Morning Musume
bryan
47
7.3k
A better future with KSS
kneath
240
18k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Speed Design
sergeychernyshev
33
1.9k
Embracing the Ebb and Flow
colly
88
5.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Practical Orchestrator
shlominoach
191
11k
Believing is Seeing
oripsolob
1
170
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
180
GraphQLとの向き合い方2022年版
quramy
50
15k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
310
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