diff --git a/static/js/bitcoin-price.js b/static/js/bitcoin-price.js index 13886cb..e437bee 100644 --- a/static/js/bitcoin-price.js +++ b/static/js/bitcoin-price.js @@ -1,13 +1,21 @@ let dataArr = []; const myChart = echarts.init(document.getElementById("chart")); -$.get("https://api.bitlab21.com/price", {}, (response) => { - dataArr = response; - console.log(dataArr); - initEchart(); -}); +async function fetchDataForChart() { + try { + const apiEndpoint = "https://api.bitlab21.com/price"; + const response = await fetch(apiEndpoint); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const dataArr = await response.json(); + initEchart(dataArr); + } catch (error) { + console.error("Fetching data failed:", error); + } +} -function initEchart() { +function initEchart(dataArr) { const option = { backgroundColor: backgroundColor, tooltip: { @@ -56,3 +64,5 @@ function initEchart() { myChart.setOption(option); } + +fetchDataForChart(); diff --git a/static/js/chart-params.js b/static/js/chart-params.js index 82481e0..5ed8368 100644 --- a/static/js/chart-params.js +++ b/static/js/chart-params.js @@ -97,7 +97,7 @@ function nFormatter(value, digits) { : "0"; } -$(window).on("resize", function () { +window.addEventListener("resize", function () { if (myChart != null && myChart != undefined) { myChart.resize(); } diff --git a/static/js/feerate-percentile.js b/static/js/feerate-percentile.js index 73ba8ad..e3a9dd9 100644 --- a/static/js/feerate-percentile.js +++ b/static/js/feerate-percentile.js @@ -1,13 +1,21 @@ let dataArr = []; const myChart = echarts.init(document.getElementById("chart")); -$.get("https://api.bitlab21.com/feerates", {}, (response) => { - dataArr = response; - console.log(dataArr); - initEchart(); -}); +async function fetchDataForChart() { + try { + const apiEndpoint = "https://api.bitlab21.com/feerates"; + const response = await fetch(apiEndpoint); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const dataArr = await response.json(); + initEchart(dataArr); + } catch (error) { + console.error("Fetching data failed:", error); + } +} -function initEchart() { +function initEchart(dataArr) { const option = { backgroundColor: backgroundColor, tooltip: { @@ -99,3 +107,4 @@ function initEchart() { myChart.setOption(option); } +fetchDataForChart(); diff --git a/static/js/hashrate.js b/static/js/hashrate.js index 9482456..3f90066 100644 --- a/static/js/hashrate.js +++ b/static/js/hashrate.js @@ -1,13 +1,21 @@ let dataArr = []; const myChart = echarts.init(document.getElementById("chart")); -$.get("https://api.bitlab21.com/hashrate", {}, (response) => { - dataArr = response; - console.log(dataArr); - initEchart(); -}); +async function fetchDataForChart() { + try { + const apiEndpoint = "https://api.bitlab21.com/hashrate"; + const response = await fetch(apiEndpoint); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const dataArr = await response.json(); + initEchart(dataArr); + } catch (error) { + console.error("Fetching data failed:", error); + } +} -function initEchart() { +function initEchart(dataArr) { const option = { backgroundColor: backgroundColor, tooltip: { @@ -106,3 +114,4 @@ function initEchart() { myChart.setOption(option); } +fetchDataForChart(); diff --git a/static/js/miner-rewards.js b/static/js/miner-rewards.js index 1a5c4d3..a2a2afc 100644 --- a/static/js/miner-rewards.js +++ b/static/js/miner-rewards.js @@ -1,13 +1,21 @@ let dataArr = []; const myChart = echarts.init(document.getElementById("chart")); -$.get("https://api.bitlab21.com/miner_rewards", {}, (response) => { - dataArr = response; - console.log(dataArr); - initEchart(); -}); +async function fetchDataForChart() { + try { + const apiEndpoint = "https://api.bitlab21.com/miner_rewards"; + const response = await fetch(apiEndpoint); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const dataArr = await response.json(); + initEchart(dataArr); + } catch (error) { + console.error("Fetching data failed:", error); + } +} -function initEchart() { +function initEchart(dataArr) { const option = { backgroundColor: backgroundColor, tooltip: { @@ -138,3 +146,4 @@ checkboxLog.addEventListener("change", (e) => { dataZoom: dataZoom((start = isChecked ? 0 : 90)), }); }); +fetchDataForChart();