ruby on rails 4 - How can I see the month and year in x axis with a Date? and values in y axis? with chartkick -
how can see month , year in x axis date? , values in y axis? chartkick
<div class="panel-body"> <%= line_chart [{name: "cantidad de voluntarios en estado activo", data: [time.new, '20'] }, {name: "study", data: [time.new, '30'] }, <!-- # how can it? --> {name: "conversation", data: [time.new, '50'] } ] , {library: {haxis: {title: "tiempo"}, vaxis: {title: "valores"}}} %> </div>
note: reply assumes using google charts charting library, appears if are.
month , year on x-axis:add option:
library: {:haxis=>{:format=>'mmm y'}}
if go google charts documentation, you'll see section on haxis.format. explain format similar icu pattern set (see http: //icu-project.org/apiref/icu4c/classsimpledateformat.html#_details).
values on y-axisi think issue have data:
alternative formatted incorrectly. (1) create values ints opposed strings (not sure if matters), , (2) key/values little off (this matters). can pass hash, data: {time.new => 20}
, or array had, except need nest array, data: [ [time.new, 20] ]
. because since it's line chart, have many many values, i.e. [ [time.new, 20], [time.new, 30], [time.new, 40] ]
in 1 series.
so, how refactored code:
<%= line_chart [ {name: "cantidad de voluntarios en estado activo", data: {time.new => 20} }, {name: "study", data: {time.new => 30} }, {name: "conversation", data: {time.new => 50} } ], {library: {haxis: {title: "tiempo", format: 'mmm y'}, vaxis: {title: "valores"}}} %>
which ends looking this:
[i can't post pics apparently, can find here: http://i.stack.imgur.com/ttvgp.png ]
hope helps!
ruby-on-rails-4 chartkick
No comments:
Post a Comment