当前位置:首页 > 新增 > 正文

新西兰币对欧元汇率:实时更新和历史图表 (新西兰币对欧元汇率)

新西兰币对欧元汇率:实时更新和历史图表 (新西兰币对欧元汇率)

实时汇率1新西兰币=0.59欧元上次更新:2023年3月8日15:30UTC历史图表过去30天的新西兰币对欧元历史汇率图表:script.jsjavascript//获...

实时汇率

1 新西兰币 = 0.59 欧元

上次更新: 2023 年 3 月 8 日 15:30 UTC

历史图表

过去 30 天的新西兰币对欧元历史汇率图表:

script.js javascript // 获取实时汇率 fetch('https://api.exchangeratesapi.io/latest?base=NZD&symbols=EUR').then(response => response.json()).then(data => {// 更新实时汇率document.getElementById('实时汇率值').innerHTML = data.rates.EUR.toFixed(4);// 更新实时汇率更新时间document.getElementById('实时汇率更新时间').innerHTML = new Date().toLocaleString();});// 创建历史图表 const canvas = document.getElementById('汇率图表'); const ctx = canvas.getContext('2d');canvas.width = window.innerWidth; canvas.height = 500;// 获取过去 30 天的汇率数据 fetch('https://api.exchangeratesapi.io/history?base=NZD&symbols=EUR&start_at=2023-02-08&end_at=2023-03-08').then(response => response.json()).then(data => {// 提取汇率数据const dates = Object.keys(data.rates);const rates = dates.map(date => data.rates[date].EUR);// 绘制图表ctx.beginPath();for (let i = 0; i < dates.length; i++) {const x = i (canvas.width / dates.length);const y = canvas.height - (rates[i] canvas.height / 0.6);if (i === 0) {ctx.moveTo(x, y);} else {ctx.lineTo(x, y);}}ctx.strokeStyle = 'blue';ctx.lineWidth = 2;ctx.stroke();// 添加图表标签ctx.fillStyle = 'black';ctx.font = '16px Arial';ctx.fillText('新西兰币对欧元汇率', 10, 20);// 添加日期标签ctx.textAlign = 'center';for (let i = 0; i < dates.length; i++) {const x = i (canvas.width / dates.length);ctx.fillText(dates[i], x, canvas.height - 10);}// 添加汇率标签ctx.textAlign = 'right';for (let i = 0; i < rates.length; i++) {const x = i (canvas.width / rates.length);const y = canvas.height - (rates[i] canvas.height / 0.6);ctx.fillText(rates[i].toFixed(4), x - 10, y + 5);}});

发表评论

最新文章