Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
ChartJS difficulty with X Axis and pulling appropriate data

I'm having some difficulties with iterating over some json data and displaying the proper X axis (Date/Time) I've tried several times to loop through the json data to extract the time for each worker in "history", but unsuccessful.

Here is a sample of the JSON - https://github.com/devdevdevdev1/rvnpoolcharts/blob/main/samplejson.json

And here is my code - https://github.com/devdevdevdev1/rvnpoolcharts/blob/main/worker_stats.js

To get it to work (somewhat), i've just thrown 48 random numbers as points on the x-axis:

displayWorkerHashrateGraph(Array.from(Array(48).keys()), dataset, label);

but obviously there are several problems with this, such as if a new worker joins after one has already been reporting, it starts at 1 and doesn't line up with the other workers.

You can see here that there is no dates/times on the x axis, and the label says 78 instead of a date label. Current Graph

I've also tried to loop through the list of each worker and extract the time like so:

let labelsList = [];
let historyList = [];
    //Begin History Loop
    for (var w in workerData.history) {
        var worker = getWorkerNameFromAddress(w);
        var a = {
            key: worker,
            hashrate: []
        };
        for (var wh in workerData.history[w]) {
            a.hashrate.push([workerData.history[w][wh].time * 1000, workerData.history[w][wh].hashrate]);
            
            
             labelsList.push([w, workerData.history[w][wh].time * 1000]);
        }
        historyList.push(a);

But that ends up looking like this - Seems its taking the time for all 3 of them, but not lining up with the hashrate and pushing all the values to the left.

What I'm trying to achieve:

  1. Pull the time value for each worker iteration from the history element, regardless of when a worker starts reporting.
  2. Mark the hashrate on the graph at the proper date/time
  3. Only display the last hour of stats (BONUS: a way to zoom out to see all 12 hours of stats)

I'd really appreciate any help you can give, I'm a bit new to javascript and I've tried many times to achieve the above and have seriously been banging my head on a wall. Thanks in advance!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!