Rickshaw is a JavaScript toolkit for creating interactive time series graphs.
Rickshaw on GitHub![](guide/images/graph_example_2.png)
Graphing Toolkit
Rickshaw provides the elements you need to create interactive graphs: renderers, legends, hovers, range selectors, etc. You put the pieces together. See Demo →
Built on d3.js
It's all based on d3 underneath, so graphs are drawn with standard SVG and styled with CSS. Customize all you like with techniques you already know.
Open Source
Rickshaw is free and open source, available under the MIT license. Developed at Shutterstock. We're Hiring!
Getting Started
Here's a minimal but complete working example. We start by pulling in dependencies. A few extensions require jQuery, but here all we need is d3 and the Rickshaw library itself. Instantiate a graph, and then render it. For more along this path, check out the tutorial and also see our examples listing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<script src="/vendor/d3.min.js"></script> | |
<script src="/vendor/d3.layout.min.js"></script> | |
<script src="/rickshaw.min.js"></script> | |
<div id="chart"></div> | |
<script> | |
var graph = new Rickshaw.Graph( { | |
element: document.querySelector("#chart"), | |
width: 300, | |
height: 200, | |
series: [{ | |
color: 'steelblue', | |
data: [ | |
{ x: 0, y: 40 }, | |
{ x: 1, y: 49 }, | |
{ x: 2, y: 38 }, | |
{ x: 3, y: 30 }, | |
{ x: 4, y: 32 } ] | |
}] | |
}); | |
graph.render(); | |
</script> |
Area Graphs
Area
standalone example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var graph = new Rickshaw.Graph({ | |
series: [ { data: [ { x: 0, y: 2 }, { x: 1, y: 4 } ... | |
renderer: 'area', | |
element: document.querySelector('#graph') | |
}); | |
graph.render(); |
Stacked Area
standalone example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var graph = new Rickshaw.Graph( { | |
element: document.querySelector("#chart"), | |
renderer: 'area', | |
stroke: true, | |
series: [ { | |
data: [ { x: 0, y: 40 }, { x: 1, y: 49 }, ... | |
color: 'steelblue' | |
}, { | |
data: [ { x: 0, y: 40 }, { x: 1, y: 49 }, ... | |
color: 'lightblue' | |
} ] | |
} ); | |
graph.render(); |
Multiple Area
standalone example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var graph = new Rickshaw.Graph( { | |
element: document.querySelector("#chart"), | |
width: 235, | |
height: 85, | |
renderer: 'area', | |
stroke: true, | |
series: [ { | |
data: [ { x: 0, y: 40 }, { x: 1, y: 49 }, ... | |
color: 'rgba(192,132,255,0.3)', | |
stroke: 'rgba(0,0,0,0.15)' | |
}, { | |
data: [ { x: 0, y: 22 }, { x: 1, y: 25 }, ... | |
color: 'rgba(96,170,255,0.5)', | |
stroke: 'rgba(0,0,0,0.15)' | |
} ] | |
} ); | |
graph.renderer.unstack = true; | |
graph.render(); |
Lines
Line
standalone example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var graph = new Rickshaw.Graph({ | |
element: document.querySelector("#chart"), | |
renderer: 'line', | |
series: [{ | |
data: [ { x: 0, y: 40 }, { x: 1, y: 49 }, ... | |
color: 'steelblue' | |
}] | |
}); | |
graph.render(); |
Multiple Line
standalone example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var graph = new Rickshaw.Graph({ | |
element: document.querySelector("#chart"), | |
renderer: 'line', | |
series: [{ | |
data: [ { x: 0, y: 40 }, { x: 1, y: 49 }, ... | |
color: 'steelblue' | |
}, { | |
data: [ { x: 0, y: 20 }, { x: 1, y: 24 }, ... | |
color: 'lightblue' | |
}] | |
}); | |
graph.render(); |
Bars
Bars
standalone examplevar graph = new Rickshaw.Graph({
element: document.querySelector("#chart"),
renderer: 'bar',
series: [{
data: [ { x: 0, y: 40 }, { x: 1, y: 49 }, ...
color: 'steelblue'
}]
});
graph.render();
Stacked Bars
standalone examplevar graph = new Rickshaw.Graph( {
element: document.querySelector("#chart"),
renderer: 'bar',
series: [{
data: [ { x: 0, y: 40 }, { x: 1, y: 49 }, ...
color: 'steelblue'
}, {
data: [ { x: 0, y: 20 }, { x: 1, y: 24 }, ...
color: 'lightblue'
}]
});
graph.render();
Multiple Bars
standalone examplevar graph = new Rickshaw.Graph( {
element: document.querySelector("#chart"),
renderer: 'bar',
stack: false,
series: [{
data: [ { x: 0, y: 40 }, { x: 1, y: 49 }, ...
color: 'steelblue'
}, {
data: [ { x: 0, y: 20 }, { x: 1, y: 24 }, ...
color: 'lightblue'
}]
});
graph.render();
Scatterplot
Scatterplot
standalone example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var graph = new Rickshaw.Graph( { | |
element: document.querySelector("#chart"), | |
renderer: 'scatterplot', | |
stroke: true, | |
series: [{ | |
data: [ { x: 0, y: 40 }, { x: 1, y: 49 }, ... | |
color: 'steelblue' | |
}] | |
} ]); | |
graph.render(); |
Interactive Legend
Add a basic legend:
var legend = new Rickshaw.Graph.Legend({Add functionality to toggle series' visibility on and off:
graph: graph,
element: document.querySelector('#graph')
});
var shelving = new Rickshaw.Graph.Behavior.Series.Toggle({Highlight each series on hover within the legend:
graph: graph,
legend: legend
});
var highlighter = new Rickshaw.Graph.Behavior.Series.Highlight({Add drag-and-drop functionality to re-order the stack (requires jQueryUI):
graph: graph,
legend: legend
});
var order = new Rickshaw.Graph.Behavior.Series.Order({
graph: graph,
legend: legend
});
Interactive Hover Details
Show the series value and formatted date and time on hover:
var hoverDetail = new Rickshaw.Graph.HoverDetail( {Specify formatting callbacks to customize output:
graph: graph
} );
var hoverDetail = new Rickshaw.Graph.HoverDetail( {See the custom formatter and subclass examples for more.
graph: graph,
xFormatter: function(x) { return x + "seconds" },
yFormatter: function(y) { return Math.floor(y) + " percent" }
} );
Annotations
Add toggleable annotations:
var annotator = new Rickshaw.Graph.Annotate({
graph: graph,
element: document.getElementById('timeline')
});
annotator.add(timestamp, message);
annotator.update();
Range Slider
Add a range selector with a slider from jQuery UI:
var slider = new Rickshaw.Graph.RangeSlider({
graph: graph,
element: document.querySelector('#slider')
});
Graphs & Data via AJAX / JSONP
Instantiate a transport to fetch the data and draw a graph:
new Rickshaw.Graph.JSONP({Transform the data before sending in, and then add other elements once that's done:
element: document.querySelector('#chart'),
dataURL: 'http://example.com/data'
});
new Rickshaw.Graph.JSONP({
element: document.querySelector('#chart'),
dataURL: 'http://example.com/data',
onData: function(d) {
d[0].data[0].y += 1;
return d;
},
onComplete: function(transport) {
var graph = transport.graph;
var detail = new Rickshaw.Graph.HoverDetail({ graph: graph });
}
});
Axes and Tick Marks
Add a basic x-axis with time values:
var xAxis = new Rickshaw.Graph.Axis.Time({Add a basic y-axis:
graph: graph
});
xAxis.render();
var yAxis = new Rickshaw.Graph.Axis.Y({Override time units on the x-axis:
graph: graph
});
yAxis.render();
var time = new Rickshaw.Fixtures.Time();Format tick values on the y-axis:
var seconds = time.unit('second');
var xAxis = new Rickshaw.Graph.Axis.Time({
graph: graph,
timeUnit: seconds
});
xAxis.render();
var yAxis = new Rickshaw.Graph.Axis.Y({For y-axes outside the graph, specify an axis container element and an orientation:
graph: graph,
tickFormat: Rickshaw.Fixtures.Number.formatKMBT
});
yAxis.render();
var yAxis = new Rickshaw.Graph.Axis.Y( {For x-axes with numeric or other non-time values:
graph: graph,
orientation: 'left',
element: document.getElementById('y_axis'),
} );
yAxis.render();
var xAxis = new Rickshaw.Graph.Axis.X( {
graph: graph
} );