baseddata.io/static/js/miner-rewards.js

128 lines
2.9 KiB
JavaScript
Raw Normal View History

2024-08-01 14:06:16 +01:00
let dataArr = [];
const myChart = echarts.init(document.getElementById("chart"));
2024-08-06 12:03:42 +01:00
async function fetchDataForChart() {
try {
const apiEndpoint =
"https://api.bitlab21.com/get_json/final__miner_rewards.json";
2024-08-06 12:03:42 +01:00
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);
}
}
2024-08-01 14:06:16 +01:00
2024-08-06 12:03:42 +01:00
function initEchart(dataArr) {
2024-08-01 14:06:16 +01:00
const option = {
backgroundColor: backgroundColor,
2024-08-08 11:53:39 +01:00
tooltip: tooltip,
2024-08-01 14:06:16 +01:00
toolbox: toolboxParams,
xAxis: {
data: dataArr.map((row) => row.date),
axisTick: axisTick,
axisLabel: axisLabel,
axisLine: axisLine,
},
grid: grid,
dataZoom: dataZoom(97),
yAxis: [
{
type: "value",
2024-08-08 14:28:01 +01:00
name: "Rewards (USD)",
2024-08-01 14:06:16 +01:00
nameLocation: "middle",
2024-08-08 11:53:39 +01:00
nameGap: 35,
nameTextStyle: textStyleMain,
2024-08-01 14:06:16 +01:00
position: "left",
alignTicks: true,
axisTick: axisTick,
axisLine: axisLine,
splitLine: {
show: false,
},
2024-08-08 11:53:39 +01:00
axisLabel: {
...axisLabel,
formatter(value, index) {
return nFormatter(value, 0);
},
},
2024-08-01 14:06:16 +01:00
},
{
type: "value",
name: "Block Subsidy (BTC)",
nameLocation: "middle",
2024-08-08 14:28:01 +01:00
nameGap: 20,
2024-08-08 11:53:39 +01:00
nameTextStyle: {
fontSize: 12 * fontScale,
color: textColor,
},
2024-08-01 14:06:16 +01:00
axisTick: axisTick,
position: "right",
alignTicks: true,
axisLine: axisLine,
splitLine: {
show: false,
},
axisLabel: {
fontSize: 12 * fontScale,
2024-08-08 11:53:39 +01:00
color: textColor,
2024-08-01 14:06:16 +01:00
},
},
],
series: [
{
type: "line",
name: "Daily Subsidy (USD)",
smooth: true,
stack: "Total",
areaStyle: {},
symbol: "none",
lineStyle: {
width: 0,
},
data: dataArr.map((row) => row.subsidy_usd),
},
{
type: "line",
name: "Daily Fees (USD)",
smooth: true,
stack: "Total",
areaStyle: {},
symbol: "none",
lineStyle: {
width: 0,
},
data: dataArr.map((row) => row.totalfee_usd),
},
{
type: "line",
name: "Daily Total Reward (USD)",
smooth: true,
symbol: "none",
lineStyle: {
width: 1,
2024-08-08 11:53:39 +01:00
color: textColor,
2024-08-01 14:06:16 +01:00
},
data: dataArr.map((row) => row.total_reward_usd),
},
{
type: "line",
yAxisIndex: 1,
name: "Block Subsidy (BTC)",
symbol: "none",
lineStyle: {
width: 3,
},
data: dataArr.map((row) => row.block_subsidy),
},
],
};
myChart.setOption(option);
}
2024-08-06 12:03:42 +01:00
fetchDataForChart();