All threads / Set a start date for Chartkick / Highcharts combination
Ask A Question


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.

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

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:

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 68,326+ 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.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.