I received an array from an ajax call (data) that I need to split into two parts:
An alert showing the data reveals:
[[200326,150000],[200327,150000],[200328,150000],[200329,150000],[200330,160000],[200331,320000]]
I attempted to extract the dates (first element) like 200326...200331 and the prices (second element) using this code:
var dates = [];
var prices= [];
var datason = JSON.parse("[" + data + "]");
for (var i in datason) {
dates.push(datason[i][0]);
prices.push(datason[i][1]);
}
The alert displaying datason shows:
200326,150000,200327,150000,200328,150000,200329,150000,200330,160000,200331,320000
Next, I want to display a canvas graph:
var chartdata = {
labels: dates,
datasets: [
{
label: 'Evolution',
backgroundColor: '#49e2ff',
borderColor: '#46d5f1',
hoverBackgroundColor: '#CCCCCC',
hoverBorderColor: '#666666',
data: prices
}
]
};
Thank you for your help!