rails line chart chartkick display the last year

164 views Asked by At

enter image description hereThis chart doesnt show me all the cases for all the years, it just show me the cases in the last year 2023. How can I display all the cases for all the years?

<%= line_chart Case.all.group_by_year(:created_at).count,
        stacked: true,
        xtitle: "Date",
        ytitle: "Transactions",
        # Additions I've tried:
        library: {
        format: 'MM/YY'
        },
        discrete: true %>
1

There are 1 answers

18
sapiv71097 On

To display all the cases for all the years in your chart, you can modify your code as follows:

<%= line_chart Case.group_by_year(:created_at),
        library: {
          xAxis: {
            type: 'datetime',
            labels: {
              format: '{value: %m/%y}'
            }
          }
        },
        xtitle: "Date",
        ytitle: "Transactions",
        discrete: true %>

It's because you're passing count of records to the chartkik. Can you pass Case.all.group_by_year(:created_at) without count instead?