All threads / Set a start date for Chartkick / Highcharts combination

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.

What do you have right now?

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 %>

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

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.

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.