baseddata.io/static/js/hashrate.js

109 lines
2.5 KiB
JavaScript

let dataArr = [];
const myChart = echarts.init(document.getElementById("chart"));
$.get("https://api.bitlab21.com/hashrate", {}, (response) => {
dataArr = response;
console.log(dataArr);
initEchart();
});
function initEchart() {
const option = {
backgroundColor: backgroundColor,
tooltip: {
backgroundColor: tooltipBgColor,
order: "seriesDesc",
valueFormatter(value, index) {
return nFormatter(value, 0);
},
textStyle: textStyleMain,
trigger: "axis",
},
toolbox: toolboxParams,
xAxis: {
data: dataArr.map((row) => row.date),
axisTick: axisTick,
axisLabel: axisLabel,
axisLine: axisLine,
},
grid: grid,
dataZoom: dataZoom(),
yAxis: [
{
type: "value",
name: "Hashrate (H/s)",
nameLocation: "middle",
nameTextStyle: {
fontSize: 12 * fontScale,
padding: [0, 0, 20, 0],
color: "#eff1d6",
},
position: "left",
alignTicks: true,
axisTick: axisTick,
splitLine: {
show: false,
},
axisLine: axisLine,
axisLabel: {
fontSize: 12 * fontScale,
color: "#eff1d6",
formatter(value, index) {
return nFormatter(value, 0);
},
},
},
{
type: "value",
name: "Difficulty",
nameLocation: "middle",
nameTextStyle: {
fontSize: 12 * fontScale,
padding: [20, 0, 0, 0],
color: "#eff1d6",
},
axisTick: axisTick,
position: "right",
alignTicks: true,
axisLine: axisLine,
splitLine: {
show: false,
},
axisLabel: {
fontSize: 12 * fontScale,
color: "#eff1d6",
formatter(value, index) {
return nFormatter(value, 0);
},
},
},
],
series: [
{
type: "line",
name: "Hashrate",
barCategoryGap: "0%",
data: dataArr.map((row) => row.hashrate),
},
{
type: "line",
color: "red",
id: "rolling-average",
name: "MA28",
showSymbol: false,
barCategoryGap: "0%",
data: dataArr.map((row) => row.hashrate28),
},
{
type: "line",
yAxisIndex: 1,
name: "Difficulty",
barCategoryGap: "0%",
data: dataArr.map((row) => row.difficulty),
},
],
};
myChart.setOption(option);
}