JSFiddle - React, Tailwind, and code Playground
by chrisguzman
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="https://rawgithub.com/NickQiZhu/dc.js/master/web/js/crossfilter.js"></script>
<script src="https://cdn.firebase.com/js/client/1.0.17/firebase.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/dc/1.7.0/dc.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<div class='pie-graph span6' id='dc-magnitude-chart'>
<h4>Events by Magnitude</h4>
</div>
JavaScript
var data = crossfilter([{
date: "2011-11-14T16:17:54Z",
quantity: 2,
total: 190,
tip: 100,
type: "tab"
}, {
date: "2011-11-14T16:20:19Z",
quantity: 2,
total: NaN,
tip: 100,
type: "tab"
}, {
date: "2011-11-14T16:28:54Z",
quantity: 1,
total: 300,
tip: 200,
type: "visa"
}, {
date: "2011-11-14T16:30:43Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T16:48:46Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T16:53:41Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T16:54:06Z",
quantity: 1,
total: NaN,
tip: null,
type: "cash"
}, {
date: "2011-11-14T17:02:03Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T17:07:21Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T17:22:59Z",
quantity: 2,
total: 90,
tip: 0,
type: "tab"
}, {
date: "2011-11-14T17:25:45Z",
quantity: 2,
total: 200,
tip: null,
type: "cash"
}, {
date: "2011-11-14T17:29:52Z",
quantity: 1,
total: 200,
tip: 100,
type: "visa"
}]);
ndx = new crossfilter(data)
var magValue = ndx.dimension(function (d) {
return d.total;
});
dc.barChart("#dc-magnitude-chart")
.width(480)
.height(150)
.margins({
top: 10,
right: 10,
bottom: 20,
left: 40
})
.dimension(magValue) // the values across the x axis
.group(magValue.group().reduceSum(function (d) {
return d.count;
})) // the values on the y axis
.transitionDuration(500)
.centerBar(true)
.gap(56) // bar width Keep increasing to get right then back off.
.x(d3.scale.linear().domain([0.5, 7.5]))
.elasticY(true)
.xAxis().tickFormat(function (v) {
return v;
});
dc.renderAll();