<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.7/crossfilter.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/dc/1.7.0/dc.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="pie-chart-sales-by-company"></div>
</body>
</html>
var data = crossfilter([
{date: new Date(2014, 1, 4), total: 1412.00, user: "Paul", status: "lead", company: "Acme"},
{date: new Date(2014, 5, 27), total: 1202.11, user: "Michael", status: "closed", company: "Acme"},
{date: new Date(2014, 6, 12), total: 412.00, user: "Paul", status: "lead", company: "Acme"},
{date: new Date(2014, 6, 22), total: 402.00, user: "John", status: "open", company: "Billings Corp"},
{date: new Date(2014, 7, 4), total: 412.00, user: "Paul", status: "closed", company: "Acme"},
{date: new Date(2014, 9, 4), total: 0, user: "Paul", status: "lead", company: "Billings Corp"},
{date: new Date(2014, 10, 4), total: 0, user: "Paul", status: "lead", company: "Coffees"},
{date: new Date(2014, 10, 1), total: 412.00, user: "Pete", status: "lost", company: "Dundler Mifflen"},
{date: new Date(2014, 11, 9), total: 3200.00, user: "John", status: "closed", company: "Dundler Mifflen"},
{date: new Date(2014, 6, 22), total: 402.00, user: "John", status: "open", company: "Billings Corp"},
{date: new Date(2014, 7, 4), total: 412.00, user: "Paul", status: "closed", company: "Acme"},
{date: new Date(2014, 9, 4), total: 0, user: "Paul", status: "lead", company: "Billings Corp"},
{date: new Date(2014, 10, 4), total: 0, user: "Paul", status: "lead", company: "Coffees"},
{date: new Date(2014, 10, 1), total: 412.00, user: "Pete", status: "lost", company: "Dundler Mifflen"},
{date: new Date(2014, 11, 9), total: 3200.00, user: "John", status: "closed", company: "Dundler Mifflen"},
{date: new Date(2014, 6, 22), total: 402.00, user: "John", status: "open", company: "Billings Corp"},
{date: new Date(2014, 7, 4), total: 412.00, user: "Paul", status: "closed", company: "Acme"},
{date: new Date(2014, 9, 4), total: 0, user: "Paul", status: "lead", company: "Billings Corp"},
{date: new Date(2014, 10, 4), total: 0, user: "Paul", status: "lead", company: "Coffees"},
{date: new Date(2014, 10, 1), total: 412.00, user: "Pete", status: "lost", company: "Dundler Mifflen"},
{date: new Date(2014, 11, 9), total: 3200.00, user: "John", status: "closed", company: "Dundler Mifflen"},
{date: new Date(2014, 6, 22), total: 402.00, user: "John", status: "open", company: "Billings Corp"},
{date: new Date(2014, 7, 4), total: 412.00, user: "Paul", status: "closed", company: "Acme"},
{date: new Date(2014, 9, 4), total: 0, user: "Paul", status: "lead", company: "Billings Corp"},
{date: new Date(2014, 10, 4), total: 0, user: "Paul", status: "lead", company: "Coffees"},
{date: new Date(2014, 10, 1), total: 412.00, user: "Pete", status: "lost", company: "Dundler Mifflen"},
{date: new Date(2014, 11, 9), total: 3200.00, user: "John", status: "closed", company: "Dundler Mifflen"},
{date: new Date(2014, 6, 22), total: 402.00, user: "John", status: "open", company: "Billings Corp"},
{date: new Date(2014, 7, 4), total: 412.00, user: "Paul", status: "closed", company: "Acme"},
{date: new Date(2014, 9, 4), total: 0, user: "Paul", status: "lead", company: "Billings Corp"},
{date: new Date(2014, 10, 4), total: 0, user: "Paul", status: "lead", company: "Coffees"},
{date: new Date(2014, 10, 1), total: 412.00, user: "Pete", status: "lost", company: "Dundler Mifflen"},
{date: new Date(2014, 11, 9), total: 3200.00, user: "John", status: "closed", company: "Dundler Mifflen"}
]);
var byTotal = function(d) {
return d.total;
}
var companyDimension = data.dimension(function(d) {return d.company;});
var totalSalesByCompany = companyDimension.group().reduceSum(byTotal);
var pieChartCompanySales = dc.pieChart("#pie-chart-sales-by-company");
pieChartCompanySales
.width(150).height(150)
.dimension(companyDimension)
.group(totalSalesByCompany)
.innerRadius(50)
.legend(dc.legend().x(80).y(70).itemHeight(13).gap(5));
dc.renderAll();
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |