Altair Todescatto F
Altair Todescatto F

Reputation: 133

Dynamic change of a chart when other option is selected

I'm working on a Ruby on Rails application, on the dashboard page, I have a chart with shows the total sales, with should have some range options, such as annual, monthly or daily. How do i update my chart when other option is selected?

.input-group.d-flex.justify-content-end
    %select#inputGroupSelect02.custom-select
        %option{:value => "1"} Diário
        %option{:value => "2"} Mensal
        %option{:value => "3"} Anual
    .input-group-append.mb-2
        %label.input-group-text{:for => "inputGroupSelect02"} Opções

.card
    .card-body.d-flex
    = column_chart Admin.group_by_day(:created_at).count

Upvotes: 0

Views: 639

Answers (1)

Valiantsin Mikhaliuk
Valiantsin Mikhaliuk

Reputation: 56

As said in documentation, you can refresh data from a remote source every n seconds

<%= line_chart url, refresh: 60 %>

or bind select event on js side and update data using chart.updateData. More in docs - https://github.com/ankane/chartkick#javascript-api

Chartkick.eachChart( function(chart) {
  chart.updateData(chart.getDataSource());
});

Upvotes: 1

Related Questions