diff --git a/c-historico/handler.cr b/c-historico/handler.cr index 59feba1..f147eb3 100644 --- a/c-historico/handler.cr +++ b/c-historico/handler.cr @@ -97,14 +97,17 @@ class Handler x = Array(Int32).new y = Array(Int32).new results = query(sql) - if results.nil? # No results, all 0s + if results.nil? # No results, all 0s x = (1922..2015).to_a - y = x.map {|_| 0} - else # We got results - displayed = true + y = x.map { |_| 0 } + else # We got results + values = Hash(Int32, Int32).new(default_value: 0) results.map { |r| - x << r[0].as_i - y << r[1].as_i + values[r[0].as_i] = r[1].as_i + } + (1922..2015).map { |year| + x << year + y << values[year] # Defaults to 0, so we have the whole set } end plot(x, y, title: nombre.titleize, style: :lines, linewidth: 3)