Ask A Question

Notifications

You’re not receiving notifications from this thread.

Set a start date for Chartkick / Highcharts combination

Stan Smith asked in Rails

This is driving me nuts.
I'm trying to set a dynamic start date of 1 month ago for a line chart using Chartkick / HighCharts.
But can't find the right syntax.

Reply

What do you have right now?

Reply

This is my helper:
def core7_by_month

line_chart User.group_by_day(:created_at).count, library: {
title: {text: 'Church members by month', x: -20},
chart: {
type: 'spline'
},
yAxis: {
crosshair: true,
allowDecimals: false,
title: {
text: 'Church Subscribers count'
}
},
xAxis: {
crosshair: true,
title: {
text: 'Year'
}
},
plotOptions: {
line: {
pointStart: 1.month.ago
}
}
}
end

This is in the view
<%= core7_by_month %>
Reply

I found the answer.
The date range parameter is handled by the groupbydate gem.
I needed to do this:
line_chart User.group_by_day(:created_at, range: 1.month.ago.midnight..Time.now).count

Reply

Perfect. Yeah the groupdate gem is handy for that stuff. You can write it yourself, but it's pretty annoying to remember it all. Works super nice with Chartkick.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.