Modify js charts to use standard js

This commit is contained in:
Sam 2024-08-06 12:03:42 +01:00
parent c014001c83
commit 5b8d0e08bc
5 changed files with 62 additions and 25 deletions

View File

@ -1,13 +1,21 @@
let dataArr = []; let dataArr = [];
const myChart = echarts.init(document.getElementById("chart")); const myChart = echarts.init(document.getElementById("chart"));
$.get("https://api.bitlab21.com/price", {}, (response) => { async function fetchDataForChart() {
dataArr = response; try {
console.log(dataArr); const apiEndpoint = "https://api.bitlab21.com/price";
initEchart(); 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 = { const option = {
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
tooltip: { tooltip: {
@ -56,3 +64,5 @@ function initEchart() {
myChart.setOption(option); myChart.setOption(option);
} }
fetchDataForChart();

View File

@ -97,7 +97,7 @@ function nFormatter(value, digits) {
: "0"; : "0";
} }
$(window).on("resize", function () { window.addEventListener("resize", function () {
if (myChart != null && myChart != undefined) { if (myChart != null && myChart != undefined) {
myChart.resize(); myChart.resize();
} }

View File

@ -1,13 +1,21 @@
let dataArr = []; let dataArr = [];
const myChart = echarts.init(document.getElementById("chart")); const myChart = echarts.init(document.getElementById("chart"));
$.get("https://api.bitlab21.com/feerates", {}, (response) => { async function fetchDataForChart() {
dataArr = response; try {
console.log(dataArr); const apiEndpoint = "https://api.bitlab21.com/feerates";
initEchart(); 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 = { const option = {
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
tooltip: { tooltip: {
@ -99,3 +107,4 @@ function initEchart() {
myChart.setOption(option); myChart.setOption(option);
} }
fetchDataForChart();

View File

@ -1,13 +1,21 @@
let dataArr = []; let dataArr = [];
const myChart = echarts.init(document.getElementById("chart")); const myChart = echarts.init(document.getElementById("chart"));
$.get("https://api.bitlab21.com/hashrate", {}, (response) => { async function fetchDataForChart() {
dataArr = response; try {
console.log(dataArr); const apiEndpoint = "https://api.bitlab21.com/hashrate";
initEchart(); 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 = { const option = {
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
tooltip: { tooltip: {
@ -106,3 +114,4 @@ function initEchart() {
myChart.setOption(option); myChart.setOption(option);
} }
fetchDataForChart();

View File

@ -1,13 +1,21 @@
let dataArr = []; let dataArr = [];
const myChart = echarts.init(document.getElementById("chart")); const myChart = echarts.init(document.getElementById("chart"));
$.get("https://api.bitlab21.com/miner_rewards", {}, (response) => { async function fetchDataForChart() {
dataArr = response; try {
console.log(dataArr); const apiEndpoint = "https://api.bitlab21.com/miner_rewards";
initEchart(); 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 = { const option = {
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
tooltip: { tooltip: {
@ -138,3 +146,4 @@ checkboxLog.addEventListener("change", (e) => {
dataZoom: dataZoom((start = isChecked ? 0 : 90)), dataZoom: dataZoom((start = isChecked ? 0 : 90)),
}); });
}); });
fetchDataForChart();