Rubyvis - Example: Line and Step Chart

Line charts are often used to visualize time series data, encoding the value of a variable over time using position. Typically, linear interpolation is used between samples. However, in some cases, the data does not vary smoothly, but instead changes in response to discrete events.
Using the interpolate property, it is easy to change this behavior for lines and areas. Rubyvis also supports various nonlinear interpolation methods, including cardinal spline, Catmull-Rom spline, B-spline, and monotone cubic.

require 'rubyvis'

data = pv.range(0, 10, 0.2).map {|x|{:x=> x, :y=> Math.sin(x) + rand() + 1.5})

vis =;

w = 400
h = 200
x = pv.Scale.linear(data, lambda {|d| d.x}).range(0, w)
y = pv.Scale.linear(0, 4).range(0, h);

#/* The root panel. */
vis =

#/* X-axis ticks. */
    .visible(lambda {|d|  d > 0})

#/* Y-axis ticks. */
    .strokeStyle(lambda {|d| d!=0 ? "#eee" : "#000"})

#/* The line. */
    .left(lambda {|d| x.scale(d.x)})
    .bottom(lambda {|d| y.scale(d.y)})



puts vis.to_svg