pullmonkey / open_flash_chart

The ruby on rails plugin for teethgrinder's Open Flash Chart (version 2)

This URL has Read+Write access

pullmonkey (author)
Thu Apr 30 08:27:39 -0700 2009
commit  7ca9f9dbea795431aafdcc3a20dd4b73900f6fba
tree    11e2e02d066efee017750e13548a19eb623c3dc2
parent  2eb746bdc51e191de09ac09a4656dca72a86cc21
open_flash_chart / lib / ofc / examples / stacked_bar_chart.rb
100644 81 lines (68 sloc) 3.502 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
module OFC
  module Examples
    module StackedBarChart
      # http://teethgrinder.co.uk/open-flash-chart-2/stacked-bar-chart.php
      def stacked_bar_chart
        #$title = new title( 'Stuff I\'m thinking about, '.date("D M d Y") );
        #$title->set_style( "{font-size: 20px; color: #F24062; text-align: center;}" );
        title = OFC::Title.new(:text => "Stuff I'm thinking about", :style => "{font-size: 20px; color: #F24062; text-align: center;}")
 
        #$bar_stack = new bar_stack();
        #// set a cycle of 3 colours:
        #$bar_stack->set_colours( array( '#C4D318', '#50284A', '#7D7B6A' ) );
        bar_stack = OFC::BarStack.new(:colours => ['#C4D318', '#50284A', '#7D7B6A'])
 
        #// add 3 bars:
        #$bar_stack->append_stack( array( 2.5, 5, 2.5 ) );
        bar_stack.values = []
        bar_stack.values << [2.5,5,2.5]
 
        #// add 4 bars, the fourth will be the same colour as the first:
        #$bar_stack->append_stack( array( 2.5, 5, 1.25, 1.25 ) );
        bar_stack.values << [2.5,5,1.25,1.25]
 
 
        #$bar_stack->append_stack( array( 5, new bar_stack_value(5, '#ff0000') ) );
        # TODO figure out BarStackValue
        bar_stack.values << [5, { "val" => 5, "colour" => "#ff0000" }]
        #$bar_stack->append_stack( array( 2, 2, 2, 2, new bar_stack_value(2, '#ff00ff') ) );
        bar_stack.values << [2,2,2,2, { "val" => 2, "colour" => "#ff00ff" }]
 
        #$bar_stack->set_keys(
        # array(
        # new bar_stack_key( '#C4D318', 'Kiting', 13 ),
        # new bar_stack_key( '#50284A', 'Work', 13 ),
        # new bar_stack_key( '#7D7B6A', 'Drinking', 13 ),
        # new bar_stack_key( '#ff0000', 'XXX', 13 ),
        # new bar_stack_key( '#ff00ff', 'What rhymes with purple? Nurple?', 13 ),
        # )
        # );
        bar_stack.keys = [{ "colour" => "#C4D318", "text" => "Kiting", "font-size" => 13 },
                          { "colour" => "#50284A", "text" => "Work", "font-size" => 13 },
                          { "colour" => "#7D7B6A", "text" => "Drinking", "font-size" => 13 },
                          { "colour" => "#ff0000", "text" => "XXX", "font-size" => 13 },
                          { "colour" => "#ff00ff", "text" => "What rhymes with purple? Nurple?", "font-size" => 13 }]
 
        #$bar_stack->set_tooltip( 'X label [#x_label#], Value [#val#]<br>Total [#total#]' );
        bar_stack.tip = "X label [#x_label#], Value [#val#]<br>Total [#total#]"
 
        #$y = new y_axis();
        #$y->set_range( 0, 14, 2 );
        y = OFC::YAxis.new(:min => 0, :max => 14, :steps => 2)
 
        #$x = new x_axis();
        #$x->set_labels_from_array( array( 'Winter', 'Spring', 'Summer', 'Autmn' ) );
        x = OFC::XAxis.new(:labels => {:lables => ["Winter", "Spring", "Summer", "Autumn"]})
 
        #$tooltip = new tooltip();
        #$tooltip->set_hover();
        tooltip = OFC::Tooltip.new
        tooltip.mouse = 2
 
        #$chart = new open_flash_chart();
        #$chart->set_title( $title );
        chart = OFC::OpenFlashChart.new(:title => title)
        #$chart->add_element( $bar_stack );
        chart.elements = []
        chart.elements << bar_stack
        #$chart->set_x_axis( $x );
        chart.x_axis = x
        #$chart->add_y_axis( $y );
        chart.y_axis = y
        #$chart->set_tooltip( $tooltip );
        chart.tooltip = tooltip
 
        #echo $chart->toPrettyString(
        render :text => chart.render
      end
    end
  end
end