fnando-chart 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +28 -2
- data/Rakefile +1 -1
- data/chart.gemspec +1 -1
- data/lib/chart/bar.rb +18 -2
- data/lib/chart/base.rb +20 -0
- data/lib/chart/grouped_bar.rb +21 -0
- metadata +1 -1
data/README.markdown
CHANGED
@@ -44,7 +44,8 @@ Just require the Chart library.
|
|
44
44
|
:margins => [50, 25],
|
45
45
|
:plot_area => [320, 180],
|
46
46
|
:labels => %w(Ruby Python Erlang),
|
47
|
-
:multicolor => false
|
47
|
+
:multicolor => false,
|
48
|
+
:angle => 45
|
48
49
|
})
|
49
50
|
|
50
51
|
chart.write("bar.png")
|
@@ -53,6 +54,28 @@ Result:
|
|
53
54
|
|
54
55
|
![Bars chart](http://f.simplesideias.com.br/chart/bar.png)
|
55
56
|
|
57
|
+
To display custom fields, use `:extra_labels` with `:label_format`:
|
58
|
+
|
59
|
+
# set some data
|
60
|
+
data = [3600.99, 1479.00, 900.10]
|
61
|
+
|
62
|
+
chart = Chart::Bar.new({
|
63
|
+
:width => 400,
|
64
|
+
:height => 240,
|
65
|
+
:data => data,
|
66
|
+
:margins => [50, 25],
|
67
|
+
:plot_area => [320, 180],
|
68
|
+
:legend => %w(Ruby Python Erlang),
|
69
|
+
:multicolor => true,
|
70
|
+
:label_format => "{={field0} * 1.6/1000|0}K ({field1})",
|
71
|
+
:inside => true,
|
72
|
+
:extra_fields => [[3000, 2000, 1600], ["FOO", "BAR", "LOL"]]
|
73
|
+
})
|
74
|
+
|
75
|
+
Result:
|
76
|
+
|
77
|
+
![Bars chart with custom fields and label format](http://f.simplesideias.com.br/chart/bar_with_extra_fields.png)
|
78
|
+
|
56
79
|
### Multicolor Bars
|
57
80
|
|
58
81
|
# set some data
|
@@ -66,7 +89,8 @@ Result:
|
|
66
89
|
:margins => [50, 25],
|
67
90
|
:plot_area => [320, 180],
|
68
91
|
:labels => %w(Jan Feb Mar),
|
69
|
-
:multicolor => true
|
92
|
+
:multicolor => true,
|
93
|
+
:label_format => nil
|
70
94
|
})
|
71
95
|
|
72
96
|
chart.write("multicolorbar.png")
|
@@ -244,6 +268,8 @@ Result:
|
|
244
268
|
|
245
269
|
![Line chart with custom symbol](http://f.simplesideias.com.br/chart/line_with_custom_symbol.png)
|
246
270
|
|
271
|
+
Check it out the `examples` directory for additional samples.
|
272
|
+
|
247
273
|
MAINTAINER
|
248
274
|
----------
|
249
275
|
|
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ PKG_FILES = %w(init.rb Rakefile chart.gemspec License.txt README.markdown) +
|
|
5
5
|
|
6
6
|
spec = Gem::Specification.new do |s|
|
7
7
|
s.name = "chart"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
s.summary = "A simple ChartDirector wrapper"
|
10
10
|
s.authors = ["Nando Vieira"]
|
11
11
|
s.email = ["fnando.vieira@gmail.com"]
|
data/chart.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
"lib/chart/pie.rb",
|
20
20
|
"lib/chart.rb"]
|
21
21
|
s.email = ["fnando.vieira@gmail.com"]
|
22
|
-
s.version = "0.0.
|
22
|
+
s.version = "0.0.3"
|
23
23
|
s.homepage = "http://github.com/fnando/chart"
|
24
24
|
s.name = "chart"
|
25
25
|
s.summary = "A simple ChartDirector wrapper"
|
data/lib/chart/bar.rb
CHANGED
@@ -18,11 +18,25 @@ module Chart
|
|
18
18
|
# set the labels
|
19
19
|
@object.xAxis.setLabels(@labels)
|
20
20
|
|
21
|
+
# set extra fields
|
22
|
+
add_extra_fields
|
23
|
+
|
21
24
|
# add data to layer
|
22
25
|
if @multicolor
|
23
|
-
@object.addBarLayer3(@data, @colors, @legend, 0)
|
26
|
+
layer = @object.addBarLayer3(@data, @colors, @legend, 0)
|
24
27
|
else
|
25
|
-
@object.addBarLayer(@data, @colors.first)
|
28
|
+
layer = @object.addBarLayer(@data, @colors.first)
|
29
|
+
end
|
30
|
+
|
31
|
+
# set label over bars
|
32
|
+
unless @label_format.nil?
|
33
|
+
if @inside
|
34
|
+
layer.setDataLabelFormat(@label_format)
|
35
|
+
layer.setDataLabelStyle("normal", 8, 0x000000, @angle)
|
36
|
+
else
|
37
|
+
layer.setAggregateLabelFormat(@label_format)
|
38
|
+
layer.setAggregateLabelStyle("normal", 8, 0x00000, @angle)
|
39
|
+
end
|
26
40
|
end
|
27
41
|
end
|
28
42
|
|
@@ -30,6 +44,8 @@ module Chart
|
|
30
44
|
def defaults!
|
31
45
|
super
|
32
46
|
@colors = Chart::COLORS
|
47
|
+
@label_format = "{value}"
|
48
|
+
@angle = 0
|
33
49
|
end
|
34
50
|
end
|
35
51
|
end
|
data/lib/chart/base.rb
CHANGED
@@ -73,6 +73,15 @@ module Chart
|
|
73
73
|
# Set line symbols
|
74
74
|
attr_accessor :symbols
|
75
75
|
|
76
|
+
# Set the angle
|
77
|
+
attr_accessor :angle
|
78
|
+
|
79
|
+
# Set extra fields for labels
|
80
|
+
attr_accessor :extra_fields
|
81
|
+
|
82
|
+
# Display label value inside bars (true|false)
|
83
|
+
attr_accessor :inside
|
84
|
+
|
76
85
|
# The ChartDirector object
|
77
86
|
attr_accessor :object
|
78
87
|
|
@@ -109,6 +118,17 @@ module Chart
|
|
109
118
|
# Set the chart defaults; should be overwritten.
|
110
119
|
def defaults!
|
111
120
|
@plot_top_margin = 50
|
121
|
+
@extra_fields = []
|
122
|
+
end
|
123
|
+
|
124
|
+
def add_extra_fields
|
125
|
+
@extra_fields.each do |fields|
|
126
|
+
if fields.any? {|i| i.class != String }
|
127
|
+
@object.addExtraField2(fields)
|
128
|
+
else
|
129
|
+
@object.addExtraField(fields)
|
130
|
+
end
|
131
|
+
end
|
112
132
|
end
|
113
133
|
end
|
114
134
|
end
|
data/lib/chart/grouped_bar.rb
CHANGED
@@ -18,6 +18,9 @@ module Chart
|
|
18
18
|
# set the labels
|
19
19
|
@object.xAxis.setLabels(@labels)
|
20
20
|
|
21
|
+
# set extra fields
|
22
|
+
add_extra_fields
|
23
|
+
|
21
24
|
# create the layer
|
22
25
|
layer = @object.addBarLayer2(ChartDirector::Side, 0)
|
23
26
|
|
@@ -25,6 +28,24 @@ module Chart
|
|
25
28
|
@data.each_with_index do |data, index|
|
26
29
|
layer.addDataSet(data, @colors[index], legend[index])
|
27
30
|
end
|
31
|
+
|
32
|
+
# set label over bars
|
33
|
+
unless @label_format.nil?
|
34
|
+
if @inside
|
35
|
+
layer.setDataLabelFormat(@label_format)
|
36
|
+
layer.setDataLabelStyle("normal", 8, 0x000000, @angle)
|
37
|
+
else
|
38
|
+
layer.setAggregateLabelFormat(@label_format)
|
39
|
+
layer.setAggregateLabelStyle("normal", 8, 0x00000, @angle)
|
40
|
+
end
|
41
|
+
end
|
28
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def defaults!
|
46
|
+
super
|
47
|
+
@label_format = "{value}"
|
48
|
+
@angle = 0
|
49
|
+
end
|
29
50
|
end
|
30
51
|
end
|