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 = [];
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();

View File

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

View File

@ -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();

View File

@ -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();

View File

@ -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();