JSFiddle - React, Tailwind, and code Playground
by humanzing
HTML
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/dataloader/dataloader.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/dark.js"></script>
<div id="chartdiv"></div>
CSS
body { background-color: #30303d; color: #fff; margin:0;}
#chartdiv {
width: 100%;
height: 100vh;
}
#chartdiv-curtain{
display:none !important ;
}
a {
display:none !important ;
}
JavaScript
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "dark",
"dataLoader": {
"url": "https://api.codetabs.com/v1/proxy?quest=https://api.binance.com/api/v1/depth?symbol=BTCUSDT&limit=1000",
"format": "json",
"reload": 0.1,
// 'skip':1,
"postProcess": function(data) {
// Function to process (sort and calculate cummulative volume)
function processData(list, type, desc) {
// Convert to data points
for(var i = 0; i < list.length; i++) {
list[i] = {
value: Number(list[i][0]),
volume: Number(list[i][1]),
}
}
// Sort list just in case
list.sort(function(a, b) {
if (a.value > b.value) {
return 1;
}
else if (a.value < b.value) {
return -1;
}
else {
return 0;
}
});
// Calculate cummulative volume
if (desc) {
for(var i = list.length - 1; i >= 0; i--) {
if (i < (list.length - 1)) {
list[i].totalvolume = list[i+1].totalvolume + list[i].volume;
}
else {
list[i].totalvolume = list[i].volume;
}
var dp = {};
dp["value"] = list[i].value;
dp[type + "volume"] = list[i].volume;
dp[type + "totalvolume"] = list[i].totalvolume;
res.unshift(dp);
}
}
else {
for(var i = 0; i < list.length; i++) {
if (i > 0) {
list[i].totalvolume = list[i-1].totalvolume + list[i].volume;
}
else {
list[i].totalvolume = list[i].volume;
}
var dp = {};
dp["value"] = list[i].value;
dp[type + "volume"] = list[i].volume;
dp[type + "totalvolume"] = list[i].totalvolume;
res.push(dp);
}
}
...