3

I've tried a simple example with the example from rickshaw...

A rest server give back a json file... If I print it to the console its exacly the same as the one from the example :

[{
        color: 'steelblue',
        data: [ 
            { x: 0, y: 40 }, 
            { x: 1, y: 49 }, 
            { x: 2, y: 38 }, 
            { x: 3, y: 30 }, 
            { x: 4, y: 32 } ]
        }]

But somehow I get alway the error " uncaught exception: series is not an array: [object Object]"

Here is my script :

var json = $.ajax({
    'url': "http://127.0.0.1:8887/getMetricsJson/metricName/water_in/earliest/1398037036/latest/1398039416",
    'success': function(json) {
        console.log(json);
    }
});


var graph = new Rickshaw.Graph( {
    element: document.getElementById("chart"),
    renderer: 'line',
    height: 200,
    width: 400,
    series: json
} );
graph.render();
OpenStove
  • 714
  • 1
  • 11
  • 22

2 Answers2

0

My solution would be to substitute "series: json.data" for "series: json" see below in context:

var graph = new Rickshaw.Graph( {
    element: document.getElementById("chart"),
    renderer: 'line',
    height: 200,
    width: 400,
    series: json.data
} );
defimeditations
  • 151
  • 1
  • 3
  • 11
  • This doesn't seem right (and I tested it and it didn't work). Looking at [this example](http://code.shutterstock.com/rickshaw/examples/data/data.json) it seems like it is correct to reference the full `json` array. – ericksonla Apr 24 '15 at 18:20
0

I think you need to parse the JSON string. I am using an XMLHttpRequest instead of ajax but that solved it for me.

This should work:

var json = $.ajax({
    'url': "http://127.0.0.1:8887/getMetricsJson/metricName/water_in/earliest/1398037036/latest/1398039416",
    'success': function(json) {
        console.log(json);
    }
});


var graph = new Rickshaw.Graph( {
    element: document.getElementById("chart"),
    renderer: 'line',
    height: 200,
    width: 400,
    series: JSON.parse(json)
} );
graph.render();

Hope this helps someone as this is a pretty old question. I couldn't find an answer anywhere else though and this question pops up when you search that error.

ericksonla
  • 1,247
  • 3
  • 18
  • 34