Sha256: dc7020fc35a7ca4f85cb64dfe09c52ecba5359e0e2cbea96f0eb69aea99a2cfd

Contents?: true

Size: 1.53 KB

Versions: 11

Compression:

Stored size: 1.53 KB

Contents

# = Bar & Column Charts
# This simple bar chart is constructed using a bar mark. A linear scale is used to compute the width of the bar, while an ordinal scale sets the top position and height for the categorical dimension. Next, rules and labels are added for reference values.
# Bars can be used in a variety of ways. For instance, they can be stacked or grouped to show multiple data series, or arranged as vertical columns rather than bars. 

$:.unshift(File.dirname(__FILE__)+"/../../lib")
require 'rubyvis'

data = pv.range(10).map {|d| rand + 0.1 }



#/* Sizing and scales. *
w = 400
h = 250
x = pv.Scale.linear(0, 1.1).range(0, w)
y = pv.Scale.ordinal(pv.range(10)).split_banded(0, h, 4/5.0)

#/* The root panel. */
vis = pv.Panel.new()
    .width(w)
    .height(h)
    .bottom(20)
    .left(20)
    .right(10)
    .top(5);

#/* The bars. */
bar = vis.add(pv.Bar)
    .data(data)
    .top(lambda { y.scale(self.index)})
    .height(y.range_band)
    .left(0)
    .width(x)

#/* The value label. */
bar.anchor("right").add(pv.Label)
    .text_style("white")
    .text(lambda {|d| "%0.1f" % d})

#/* The variable label. */
bar.anchor("left").add(pv.Label)
    .text_margin(5)
    .text_align("right")
    .text(lambda { "ABCDEFGHIJK"[self.index,1]});
 
#/* X-axis ticks. */
vis.add(pv.Rule)
    .data(x.ticks(5))
    .left(x)
    .stroke_style(lambda {|d|  d!=0 ? "rgba(255,255,255,.3)" : "#000"})
  .add(pv.Rule)
    .bottom(0)
    .height(5)
    .stroke_style("#000")
  .anchor("bottom").add(pv.Label)
  .text(x.tick_format);

vis.render();
puts vis.to_svg

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rubyvis-0.7.0 examples/3_pv_conventional/bar_column_chart.rb
rubyvis-0.6.1 examples/3_pv_conventional/bar_column_chart.rb
rubyvis-0.6.0 examples/3_pv_conventional/bar_column_chart.rb
rubyvis-0.5.2 examples/3_pv_conventional/bar_column_chart.rb
rubyvis-0.5.1 examples/3_pv_conventional/bar_column_chart.rb
rubyvis-0.5.0 examples/3_pv_conventional/bar_column_chart.rb
rubyvis-0.4.1 examples/3_pv_conventional/bar_column_chart.rb
rubyvis-0.4.0 examples/3_pv_conventional/bar_column_chart.rb
rubyvis-0.3.6 examples/3_pv_conventional/bar_column_chart.rb
rubyvis-0.3.5 examples/3_pv_conventional/bar_column_chart.rb
rubyvis-0.3.4 examples/3_pv_conventional/bar_column_chart.rb