Set a start date for Chartkick / Highcharts combination
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
}
}
}
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.