Skip to content

Instantly share code, notes, and snippets.

@laurenschroeder
Last active April 12, 2017 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laurenschroeder/bb42e165ca76e070566e75ccbfba0e89 to your computer and use it in GitHub Desktop.
Save laurenschroeder/bb42e165ca76e070566e75ccbfba0e89 to your computer and use it in GitHub Desktop.
Fast Food Sales

A simple barchart to visualize sales of different fast food companies.

The graphics in the original chart distorted the data and made the image difficult to understand. Interactions could be implimented to add graphics in a subtle way.

Original image, found in Business Insider's article 'The 27 Worst Charts of All Time': http://www.businessinsider.com/the-27-worst-charts-of-all-time-2013-6?op=1/#burger-king-has-3-times-as-much-in-sales-than-starbucks-it-makes-sense-that-its-three-times-taller-but-the-fact-that-its-area-is-nine-times-that-of-starbucks-shows-why-this-chart-exemplifies-everything-that-is-wrong-with-charts-that-try-to-incorporate-cutesy-graphics-2

Company|Sales (Billion USD)
Starbucks|4.1
Taco Bell|4.3
Pizza Hut|8
KFC|8.2
Wendy's|9.4
Burger King|11.3
McDonald's|41
<!DOCTYPE html>
<html>
<head>
<style>
rect.dimple-series-0 {
fill: red;
}
rect.dimple-series-0:hover {
fill: yellow;
}
</style>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://dimplejs.org/dist/dimple.v2.0.0.min.js"></script>
<script type="text/javascript">
function draw(data) {
/*
D3.js setup code
*/
"use strict";
var margin = 75,
width = 1400 - margin,
height = 600 - margin;
var svg = d3.select("body")
.append("svg")
.attr("width", width + margin)
.attr("height", height + margin)
.append('g')
.attr('class','chart');
/*
Dimple.js Chart construction code
*/
var myChart = new dimple.chart(svg, data);
var y = myChart.addCategoryAxis("y", "Company");
var x = myChart.addMeasureAxis("x", "Sales (Billion USD)");
x.fontSize = "auto";
y.fontSize = "auto";
myChart.addSeries(null, dimple.plot.bar);
myChart.draw();
};
</script>
</head>
<body>
<script type="text/javascript">
/*
Use D3 (not dimple.js) to load the text file
and pass the contents of it to the draw function
*/
psv = d3.dsv("|","text/plain");
psv("fastfood.txt",draw);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment