Skip to content

Commit

Permalink
[financial] use numeric x-axis for even spacing (squash weekends)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeoniya committed Nov 7, 2019
1 parent b193d46 commit d3b3985
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion demos/high-low-bands.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
[1282.85,1315,1318.7,1309.6,1317.6,1312.9,1312.4,1319.1,1319,1321,1318.1,1321.3,1319.9,1312,1280.5,1276.15,1308,1309.9,1308.5,1312.3,1329.3,1333.1,1340.2,1347,1345.9,1338,1340.8,1335,1332,1337.9,1333,1336.8,1333.2,1329.9,1340.4,1323.85,1324.05,1349,1366.3,1351.2,1349.1,1352.4,1350.7,1344.3,1338.9,1316.3,1308.4,1306.9,1309.6,1306.7,1312.3,1315.4,1319,1327.2,1317.2,1320,1323,1328,1323,1327.8,1331.7,1335.3,1336.6,1331.8,1311.4,1310,1309.5,1308,1310.6,1302.8,1306.6,1313.7,1320,1322.8,1311,1312.1,1303.6,1293.9,1293.5,1291,1277.9,1294.1,1286,1289.1,1293.5,1296.9,1298,1299.6,1292.9,1285.1,1288.5,1296.3,1297.2,1298.4,1298.6,1302,1300.3,1312,1310.8,1301.9,1292,1291.1,1286.3,1289.2,1289.9,1297.4,1283.65,1283.25,1292.9,1295.9,1290.8,1304.2,1322.7,1336.1,1341,1343.5,1345.8,1340.3,1335.1,1341.5,1347.6,1352.8,1348.2,1353.7,1356.5,1373.3,1398,1414.7,1427,1416.4,1412.7,1420.1,1396.4,1398.8,1426.6,1412.85,1400.7,1406,1399.8,1404.4,1415.5,1417.2,1421.9,1415,1413.7,1428.1,1434,1435.7,1427.5,1429.4,1423.9,1425.6,1427.5,1434.8,1422.3,1412.1,1442.5,1448.8,1468.2,1484.3,1501.6,1506.2,1498.6,1488.9,1504.5,1518.3,1513.9,1503.3,1503,1506.5,1502.1,1503,1534.8,1535.3,1541.4,1528.6,1525.6,1535.25,1528.15,1528,1542.6,1514.3,1510.7,1505.5,1492.1,1492.9,1496.8,1493.1,1503.4,1500.9,1490.7,1496.3,1505.3,1505.3,1517.9,1507.4,1507.1,1493.3,1470.5,1465,1480.5,1501.7,1501.4,1493.3,1492.1,1505.1,1495.7,1478,1487.1,1480.8,1480.6,1487,1488.3,1484.8,1484,1490.7,1490.4,1503.1],
];

let dates = gold[0];
// create a [0...N] int array in place of timestamps
gold[0] = Array.apply(null, {length: gold[0].length}).map(Function.call, Number);
let stamp = uPlot.fmtDate('{MM}/{DD}/{YY}');
let fmtDate = idx => {
let d = uPlot.tzDate(new Date(dates[idx] * 1e3), 'Etc/UTC');
return stamp(d);
};

function fmtUSD(val, dec) {
return "$" + val.toFixed(dec).replace(/\d(?=(\d{3})+(?:\.|$))/g, '$&,');
}
Expand All @@ -41,8 +50,16 @@
width: 1920,
height: 600,
title: "Gold",
tzDate: ts => uPlot.tzDate(new Date(ts * 1e3), 'Etc/UTC'),
// tzDate: ts => uPlot.tzDate(new Date(ts * 1e3), 'Etc/UTC'),
scales: {
x: {
time: false,
}
},
series: {
x: {
value: fmtDate,
},
y: [
{
label: "Low",
Expand Down Expand Up @@ -70,6 +87,9 @@
],
},
axes: {
x: {
values: vals => vals.map(fmtDate),
},
y: [
{
values: vals => vals.map(v => fmtUSD(v, 0))
Expand Down

0 comments on commit d3b3985

Please sign in to comment.