mardi 30 juin 2015

Hooking ember-highcharts onto a rails API endpoint

I am trying to use Ember Highcharts to render some charts in EmberJS.

I have the component working with static data, by setting it in the controller as per the instructions:

chartData: [
  {
    name: 'Jane',
    data: [1, 0, 4]
  }, {
    name: 'John',
    data: [5, 7, 3]
  }
],

However, I'm not really sure how to hook the chartData property onto my rails API data. I am using Ember Data for the rest of my app but I thought that I should avoid it for the charts aspect as the chart data doesn't correspond to a particular model so it will get a bit messy. I thought that maybe something like this would work:

chartData: $.getJSON('api.enerlytics.local.dev:3000/v1/chart_data/4'),

but the chart is blank.

(NB: my rails API is returning the data in this format, maybe it's the extra root element that is causing issues?)

{
  "chart_data": [
    {
      "name": "First",
      "data": [
        [
          1214265600000,
          1
        ],
        [
          1214352000000,
          2
        ],
        [
          1214438400000,
          3
        ],
        [
          1214524800000,
          4
        ],
        [
          1214784000000,
          5
        ]
      ]
    },
    {
      "name": "Second",
      "data": [
        [
          1214265600000,
          5
        ],
        [
          1214352000000,
          4
        ],
        [
          1214438400000,
          3
        ],
        [
          1214524800000,
          2
        ],
        [
          1214784000000,
          1
        ]
      ]
    }
  ]
}




Aucun commentaire:

Enregistrer un commentaire