rickshaw下载 - 一款创建交互式实时图形的简单js库

6382 2018-05-07 JavaScript MIT 官方网站

Rickshaw一款基于 Mike Bostock’s delightful D3 库开发的用于创建交互式实时图形的简单js库。


v1.6.4.zip(v1.6.6) 下载

v1.6.5.zip(v1.6.6) 下载

v1.6.6.zip(v1.6.6) 下载

v1.6.2.zip(v1.6.2) 下载



Rickshaw is a JavaScript toolkit for creating interactive time series graphs, developed at Shutterstock

Table of Contents

Getting Started

Getting started with a simple graph is straightforward.  Here's the gist:

var graph = new Rickshaw.Graph( {
  element: document.querySelector('#graph'),
  series: [
      color: 'steelblue',
      data: [ { x: 0, y: 23}, { x: 1, y: 15 }, { x: 2, y: 79 } ]
    }, {
      color: 'lightblue',
      data: [ { x: 0, y: 30}, { x: 1, y: 20 }, { x: 2, y: 64 } ]
} );


See the overview, tutorial, and examples for more.


In the browser, manually add rickshaw.min.js and rickshaw.min.css in the document head.

Alternatively, you can install Rickshaw using Bower or npm.

# With bower
bower install rickshaw
# With npm
npm install --save rickshaw


Rickshaw relies on the fantastic D3 visualization library to do lots of the heavy lifting for stacking and rendering to SVG.

Some extensions require jQuery and jQuery UI, but for drawing some basic graphs you'll be okay without.

Rickshaw uses jsdom to run unit tests in Node to be able to do SVG manipulation. As of the jsdom 7.0.0 release, jsdom requires Node.js 4 or newer jsdom changelog. If you want to run the tests on your machine, and you don't have access to a version of node >= 4.0, you can npm install jsdom@3  so that you can run the tests using the 3.x branch of jsdom.


A Rickshaw graph.  Send an element reference, series data, and optionally other properties to the constructor before calling render() to point the graph.  A listing of properties follows.  Send these as arguments to the constructor, and optionally set them later on already-instantiated graphs with a call to configure()


A reference to an HTML element that should hold the graph.


Array of objects containing series data to plot.  Each object should contain data at a minimum, a sorted array of objects each with x and y properties.  Optionally send a name and color as well.  Some renderers and extensions may also support additional keys.


A string containing the name of the renderer to be used.  Options include area, stack, bar, line, and scatterplot.  Defaults to line. Also see the multi meta renderer in order to support different renderers per series.


Width of the graph in pixels.  Falls back to the width of the element, or defaults to 400 if the element has no width.


Height of the graph in pixels.  Falls back to the height of the element, or defaults to 250 if the element has no height.


Lower value on the Y-axis, or auto for the lowest value in the series.  Defaults to 0.


Highest value on the Y-axis.  Defaults to the highest value in the series.


An object containing any of top, right, bottom, and left properties specifying a padding percentage around the extrema of the data in the graph.  Defaults to 0.01 on top for 1% padding, and 0 on other sides. Padding on the bottom only applies when the yMin is either negative or auto.


Line smoothing / interpolation method (see D3 docs); notable options:

  • linear: straight lines between points

  • step-after: square steps from point to point

  • cardinal: smooth curves via cardinal splines (default)

  • basis: smooth curves via B-splines


Allows you to specify whether series should be stacked while in the context of stacking renderers (area, bar, etc).  Defaults to stack: 'true'. To unstack, unstack: 'true'.


Once you have instantiated a graph, call methods below to get pixels on the screen, change configuration, and set callbacks.


Draw or redraw the graph.


Set properties on an instantiated graph.  Specify any properties the constructor accepts, including width and height and renderer.  Call render() to redraw the graph and reflect newly-configured properties.


Add a callback to run when the graph is rendered


Once you have a basic graph, extensions let you add functionality.  See the overview and examples listing for more.

  • Rickshaw.Graph.Legend - add a basic legend

  • Rickshaw.Graph.HoverDetail - show details on hover

  • Rickshaw.Graph.JSONP - get data via a JSONP request

  • Rickshaw.Graph.Annotate - add x-axis annotations

  • Rickshaw.Graph.RangeSlider - dynamically zoom on the x-axis with a slider

  • Rickshaw.Graph.RangeSlider.Preview - pan and zoom via graphical preview of entire data set

  • Rickshaw.Graph.Axis.Time - add an x-axis and grid lines with time labels

  • Rickshaw.Graph.Axis.X - add an x-axis and grid lines with arbitrary labels

  • Rickshaw.Graph.Axis.Y - add a y-axis and grid lines

  • Rickshaw.Graph.Axis.Y.Scaled - add a y-axis with an alternate scale

  • Rickshaw.Graph.Behavior.Series.Highlight - highlight series on legend hover

  • Rickshaw.Graph.Behavior.Series.Order - reorder series in the stack with drag-and-drop

  • Rickshaw.Graph.Behavior.Series.Toggle - toggle series on and off through the legend


Rickshaw comes with a few color schemes. Instantiate a palette and specify a scheme name, and then call color() on the palette to get each next color.

var palette = new Rickshaw.Color.Palette( { scheme: 'spectrum2001' } );

palette.color() // => first color in the palette
palette.color() // => next color in the palette...

Optionally, to palette.color() can take a numeric argument to specify which color from the palette should be used (zero-indexed).  This can be helpful when assigning a color to series of a plot with particular meaning:

var palette = new Rickshaw.Color.Palette( { scheme: 'colorwheel' } );

palette.color(0) // => first color in the palette - red in this example
palette.color(2) // => third color in the palette - light blue

Color Schemes

  • classic9

  • colorwheel

  • cool

  • munin

  • spectrum14

  • spectrum2000

  • spectrum2001


For graphs with more series than palettes have colors, specify an interpolatedStopCount to the palette constructor.

Rickshaw and Cross-Browser Support

This library works in modern browsers and Internet Explorer 9+.

Rickshaw relies on the HTMLElement#classList API, which isn't natively supported in Internet Explorer 9.  Rickshaw adds support by including a shim which implements the classList API by extending the HTMLElement prototype.  You can disable this behavior if you like, by setting RICKSHAW_NO_COMPAT to a true value before including the library.


If your project uses minification, you will need to give a hint to the minifier to leave variables named $super named $super.  For example, with uglify on the command line:

$ uglify-js --reserved-names "$super" rickshaw.js > rickshaw.min.js

Or a sample configuration with grunt-contrib-uglify:

uglify: {
  options: {
    mangle: { except: ["$super"] }


For building, we use Node and npm. Running npm run build or make should get you going with any luck.

After doing a build you can run the tests with the command: npm test

For more availible options see the package.json scripts section.