Я пытаюсь построить диаграмму с помощью библиотеки chart.js. В настоящее время я пытаюсь построить данные файла json.
Это код, с помощью которого я могу получить значения свойств сектора и страны.
const xs = [];
const ys = [];
const api_url = 'jsondata.json';
async function getData() {
const response = await fetch(api_url);
const data = await response.json();
const sector = data.map(prop => prop.sector);
xs.push(sector);
console.log(sector);
const country = data.map(prop => prop.country);
xs.push(country);
console.log(country);
}
getData();
Мой файл JSON выглядит следующим образом:
[{
"end_year": "",
"intensity": 6,
"sector": "Energy",
"published": "January, 09 2017 00:00:00",
"country": "United States of America",
},
{
"end_year": "",
"intensity": 6,
"sector": "Energy",
"published": "January, 09 2017 00:00:00",
"country": "United States of America",
}
]
Я пытаюсь получить значения этих свойств и использовать их в качестве меток для оси X и Y соответственно.