2

Is it possible to use ng-href="{{userData}}" in chartkick for rails? What I want to do is something like:

<%= line_chart ng-href='{{userData}}' %>

When my angular app loads up, I call .run like this:

kpiApp.run(function($rootScope, $http){
    $http.get('kpis/kpi_users_count.json').then(function (response) {
        $rootScope.userData = response.data;
    });
});

I can see it works because on my page {{userData}} renders the expected json, now I want to insert this as the data attribute as the chartkick documentation indicates:

<%= line_chart data, id: "users-chart", height: "500px" %>

Thanks for any advice.

Slenny
  • 379
  • 2
  • 4
  • 13
  • 1
    You can't do this using ruby helper, ruby executes server side ages before angular kicks in. Chartkick gem is only a ruby wrapper for chartkick.js, if you want your chartkick working with angular, you need to use unwrapped version: https://github.com/ankane/chartkick.js. It is a chance to contribute - create angular module for chartick! – BroiSatse Feb 02 '16 at 15:50
  • @BrioSatse, yeah, I think you're right. What I ended up doing was creating an angular Directive with a link function to insert in a new chart on some $interval. I just need it updated about every 15 mins, so that works ok. thanks. – Slenny Feb 02 '16 at 23:32

0 Answers0