将数据从对象传递到数组

问题描述 投票:0回答:1

我尝试绘制汇率图表,向银行提出请求,并获取包含有关汇率数据的对象数组。而且我需要将值从对象传输到图表上显示的数组

这里有一个对象数组

 var dataArr = [];
async function currency(e) {

var sdate=startdate.value.split("-").join("");
var edate=enddate.value.split("-").join("");
 for (var i = Number(sdate); i <= Number(edate); i++){
	await delay(2000)
	let url=`https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?valcode=${currenc.value}&date=${i}&json`;
let response= await fetch(url);
let data =await response.json();
var itemObj={
	rate:data[0].rate,
	exchangedate:data[0].exchangedate
	};
	dataArr.push(itemObj);
}
console.log(dataArr);

}

这里我需要将数据字段传递给序列数组

Highcharts.chart('container', {

    title: {
        text: 'Графік курса валют'
    },

    subtitle: {
        text: ''
    },

    yAxis: {
        title: {
            text: 'Зріст'
        }
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },

    plotOptions: {
        series: {
            label: {
                connectorAllowed: false
            },
            pointStart: 2010
        }
    },

    series: [{
        name: '',
        data: []        //OVER HERE!!!
    }, {
       
    }],

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            chartOptions: {
                legend: {
                    layout: 'horizontal',
                    align: 'center',
                    verticalAlign: 'bottom'
                }
            }
        }]
    }

});
javascript ajax highcharts
1个回答
0
投票

不确定我是否正确理解了您的问题...如果在这种情况下可以访问数组变量“ dataArr”,则可以分配数据:dataArr像这样:

Highcharts.chart('container', {

    title: {
        text: 'Графік курса валют'
    },

    subtitle: {
        text: ''
    },

    yAxis: {
        title: {
            text: 'Зріст'
        }
    },
    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },

    plotOptions: {
        series: {
            label: {
                connectorAllowed: false
            },
            pointStart: 2010
        }
    },

    series: [{
        name: '',
        data: dataArr        //OVER HERE!!!
    }, {

    }],

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            chartOptions: {
                legend: {
                    layout: 'horizontal',
                    align: 'center',
                    verticalAlign: 'bottom'
                }
            }
        }]
    }

});
© www.soinside.com 2019 - 2024. All rights reserved.