# Scruffy Stacked Bar Chart

**URL:** <https://www.ruby-forum.com/t/scruffy-stacked-bar-chart/130604>\
**Category:** Rails\
**Created:** [February 29, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/scruffy-stacked-bar-chart/130604 "2008-02-29T18:59:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [February 29, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/scruffy-stacked-bar-chart/130604/1 "2008-02-29T18:59:19Z")

</div>

Hi-

Trying to do a stacked bar chart, but nothing is rendering when I add  
more then 1 bar:

This works:  
graph = Scruffy::Graph.new(:title =\> “My Chart”)  
graph.add :stacked do |stack|  
stack.add(:bar, ‘Stack1’, [10,10])  
end

This doesn’t:  
graph = Scruffy::Graph.new(:title =\> “My Chart”)  
graph.add :stacked do |stack|  
stack.add(:bar, ‘Stack1’, [10,10])  
stack.add(:bar, ‘Stack2’, [15,10])  
end

Anyone know what’s going wrong here?

Thanks!

---

<div class="post-metadata">

**Author:** ![pete](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3ab097/32.png) [@pete](https://www.ruby-forum.com/u/pete)\
**Post date:** [May 29, 2008, 1:31am UTC](https://www.ruby-forum.com/t/scruffy-stacked-bar-chart/130604/2 "2008-05-29T01:31:23Z")

</div>

pete wrote:

> Hi-
> 
> Trying to do a stacked bar chart, but nothing is rendering when I add  
> more then 1 bar:
> 
> This works:  
> graph = Scruffy::Graph.new(:title =\> “My Chart”)  
> graph.add :stacked do |stack|  
> stack.add(:bar, ‘Stack1’, [10,10])  
> end
> 
> This doesn’t:  
> graph = Scruffy::Graph.new(:title =\> “My Chart”)  
> graph.add :stacked do |stack|  
> stack.add(:bar, ‘Stack1’, [10,10])  
> stack.add(:bar, ‘Stack2’, [15,10])  
> end
> 
> Anyone know what’s going wrong here?

There’s a small bug in an inject call inside the “points” method of the  
Stacked layer class. You need to replace this line (71 in my copy of  
the source)

longest = layer.points if (longest.nil? || longest.size \<  
layer.points.size)

with this one

layer.points if (longest.nil? || longest.size \< layer.points.size)

At least, that worked for me. YMMV :-).
