Popular a Chart.js with ajax.get

0

Speak, I have a question here in my project. I have a chart that looks like this:

And I want it popular with the data of a webservice in PHP, which will return a JSON and in every button it clicks, I make a new request. Knowing that the method of storing his data is like this:

data: [ [1, 34], [2, 25], [3, 19], [4, 34], [5, 32], [6, 44] ] };

Now my question is: How do I allocate data in this way on the 'date' of the chart? Assuming my JSON looks like this:

   [
    {
        "content":[
            {
                "data": "2015-05-05",
                "volume": "280"
            },
            {
                "data": "2015-05-06",
                "volume": "20"
            }
        ]
    }
]

I've had difficulty using ajax request data in graphics and I ended up leaving pig with PHP in the middle, but this time there is no way haha. If anyone knows how to help, I will be grateful. Hugs.

    
asked by anonymous 07.03.2016 / 21:56

1 answer

0

Using JSON.parse it is possible to access the data within the returned JSON, as shown in the example below:

var retorno =
{
    "content":[
        {
            "data": "2015-05-05",
            "volume": "280"
        },
        {
            "data": "2015-05-06",
            "volume": "20"
        }
    ]
}
objeto = JSON.parse(retorno);
objeto.content[1].data; // "2015-05-05"
objeto.content[1].volume; // "280"
objeto.content[2].data; // "2015-05-06"
objeto.content[2].volume; // "20"
    
08.03.2016 / 00:55