Chartjs-Parsing an unnamed JSON array into React component

0👍

Try this out:

var data = [
  {
    "asset_id": "DOGE",
    "name": "DogeCoin",
    "type_is_crypto": 1,
    "data_start": "2014-02-21",
    "data_end": "2021-02-13",
    "data_quote_start": "2014-07-31T13:05:46.0000000Z",
    "data_quote_end": "2021-02-13T18:11:23.9210000Z",
    "data_orderbook_start": "2014-07-31T13:05:46.0000000Z",
    "data_orderbook_end": "2020-08-05T14:37:58.7197513Z",
    "data_trade_start": "2014-02-21T05:16:16.8330000Z",
    "data_trade_end": "2021-02-13T18:12:51.7190000Z",
    "data_symbols_count": 5087,
    "volume_1hrs_usd": 2344753752.07,
    "volume_1day_usd": 90403357198.90,
    "volume_1mth_usd": 12757493880306.16,
    "price_usd": 0.06774975,
    "id_icon": "63e240f3-047f-41c7-9179-6784bc719f63"
  },
  {
    "asset_id": "ADA",
    "name": "Cardano",
    "type_is_crypto": 1,
    "data_start": "2017-09-29",
    "data_end": "2021-02-13",
    "data_quote_start": "2017-09-29T07:11:06.6463948Z",
    "data_quote_end": "2021-02-13T18:11:58.5984612Z",
    "data_orderbook_start": "2017-09-29T07:11:06.6463948Z",
    "data_orderbook_end": "2020-08-05T14:37:58.7010000Z",
    "data_trade_start": "2017-10-01T20:08:31.0000000Z",
    "data_trade_end": "2021-02-13T18:12:42.5550000Z",
    "data_symbols_count": 291,
    "volume_1hrs_usd": 115032462.37,
    "volume_1day_usd": 3962452344.40,
    "volume_1mth_usd": 147189367042.86,
    "price_usd": 0.873287,
    "id_icon": "2701173b-1b77-40f2-8693-9659359e225c"
  }
]

var labels = [];
var prices = [];

data.forEach(entry => {
    labels.push(entry["asset_id"]);
    prices.push(entry["price_usd"]);
});

console.log('labels: ', labels);
console.log('data: ', prices);

Leave a comment