baseddata.io/static/js/feerate-percentile.js

108 lines
2.4 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/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);
}
}
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,
tooltip: {
2024-08-08 11:53:39 +01:00
...tooltip,
2024-08-01 14:06:16 +01:00
valueFormatter: (value) => `${value.toFixed(0)} sats/vByte`,
},
toolbox: toolboxParams,
xAxis: {
data: dataArr.map((row) => row.date),
axisTick: axisTick,
axisLabel: axisLabel,
axisLine: axisLine,
},
yAxis: {
axisTick: axisTick,
splitLine: {
show: false,
},
axisLabel: axisLabel,
axisLine: axisLine,
},
grid: grid,
dataZoom: dataZoom((start = 98)),
series: [
{
type: "line",
id: "min-feerate",
name: "min",
showSymbol: false,
barCategoryGap: "0%",
data: [0],
},
{
type: "bar",
stack: "value",
name: "10th",
barCategoryGap: "0%",
data: dataArr.map((row) => row.feerate_10th),
},
{
type: "bar",
stack: "value",
name: "25th",
barCategoryGap: "0%",
data: dataArr.map((row) => row.feerate_25th),
},
{
type: "bar",
stack: "value",
name: "50th",
barCategoryGap: "0%",
data: dataArr.map((row) => row.feerate_50th),
},
{
type: "line",
id: "mean-feerate",
name: "mean",
showSymbol: false,
barCategoryGap: "0%",
data: [0],
},
{
type: "bar",
stack: "value",
name: "75th",
barCategoryGap: "0%",
data: dataArr.map((row) => row.feerate_75th),
},
{
type: "bar",
stack: "value",
name: "90th",
barCategoryGap: "0%",
data: dataArr.map((row) => row.feerate_90th),
},
{
type: "line",
id: "max-feerate",
name: "max",
showSymbol: false,
barCategoryGap: "0%",
data: [0],
},
],
};
myChart.setOption(option);
}
2024-08-06 12:03:42 +01:00
fetchDataForChart();