128 lines
2.9 KiB
JavaScript
128 lines
2.9 KiB
JavaScript
let dataArr = [];
|
|
const myChart = echarts.init(document.getElementById("chart"));
|
|
|
|
async function fetchDataForChart() {
|
|
try {
|
|
const apiEndpoint =
|
|
"https://api.baseddata.io/get_json/final__miner_rewards.json";
|
|
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(dataArr) {
|
|
const option = {
|
|
backgroundColor: backgroundColor,
|
|
tooltip: tooltip,
|
|
toolbox: toolboxParams,
|
|
xAxis: {
|
|
data: dataArr.map((row) => row.date),
|
|
axisTick: axisTick,
|
|
axisLabel: axisLabel,
|
|
axisLine: axisLine,
|
|
},
|
|
grid: grid,
|
|
dataZoom: dataZoom(97),
|
|
yAxis: [
|
|
{
|
|
type: "value",
|
|
name: "Rewards (USD)",
|
|
nameLocation: "middle",
|
|
nameGap: 35,
|
|
nameTextStyle: textStyleMain,
|
|
position: "left",
|
|
alignTicks: true,
|
|
axisTick: axisTick,
|
|
axisLine: axisLine,
|
|
splitLine: {
|
|
show: false,
|
|
},
|
|
axisLabel: {
|
|
...axisLabel,
|
|
formatter(value, index) {
|
|
return nFormatter(value, 0);
|
|
},
|
|
},
|
|
},
|
|
{
|
|
type: "value",
|
|
name: "Block Subsidy (BTC)",
|
|
nameLocation: "middle",
|
|
nameGap: 20,
|
|
nameTextStyle: {
|
|
fontSize: 12 * fontScale,
|
|
color: textColor,
|
|
},
|
|
axisTick: axisTick,
|
|
position: "right",
|
|
alignTicks: true,
|
|
axisLine: axisLine,
|
|
splitLine: {
|
|
show: false,
|
|
},
|
|
axisLabel: {
|
|
fontSize: 12 * fontScale,
|
|
color: textColor,
|
|
},
|
|
},
|
|
],
|
|
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,
|
|
color: textColor,
|
|
},
|
|
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);
|
|
}
|
|
|
|
fetchDataForChart();
|