Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert method between timestamp unaware collection and TimestampedValue #12

Closed
lcallarec opened this issue Apr 11, 2020 · 3 comments
Closed

Comments

@lcallarec
Copy link
Owner

Works like a charm 😌️
Built in conversion to a TimestampedValue would be awesome πŸ€“
Screen record from 2020-04-09 23 05 43
.

Originally posted by @stsdc in #8 (comment)

@lcallarec
Copy link
Owner Author

Hey @stsdc,

Since LiveChart 1.4.0, you can import your data in a much easier way.

Instead of :

var renderer = new LiveChart.SmoothLineArea();
var cpu = new LiveChart.Serie("CPU", renderer);

var chart = new LiveChart.Chart();
chart.add_serie(cpu);
//Other stuff

//To add the CPU history 

var values = renderer.get_values();
values.clear(); // Clear all the data

//Here's your own data from ArrayList<double>
var cpu_history = new Gee.ArrayList<double?>();
cpu_history.add(10);
cpu_history.add(30);
cpu_history.add(20);
cpu_history.add(40);
cpu_history.add(20);
cpu_history.add(60);
cpu_history.add(30);
cpu_history.add(90);

var refresh_rate_is_ms = 2000; //your own refresh rate in milliseconds
var now = GLib.get_real_time() / 1000; //now in milliseconds

//the  timestamp of the first point
//we are considering that it is "now", but because of your data structure
//it can be between now and now - 2secs), we can't guess
var ts = now - (cpu_history.size * refresh_rate_is_ms); 

cpu_history.foreach((value) => {
    values.add({ts, value});    
    ts += refresh_rate_is_ms;
    return true;
});

You can write :

var cpu = new LiveChart.Serie("CPU", new LiveChart.SmoothLineArea(););
var chart = new LiveChart.Chart();
chart.add_serie(cpu);

//Here's your own data from ArrayList<double>
var cpu_history = new Gee.ArrayList<double?>();
cpu_history.add(10);
cpu_history.add(30);
cpu_history.add(20);
cpu_history.add(40);
cpu_history.add(20);
cpu_history.add(60);
cpu_history.add(30);
cpu_history.add(90);

var refresh_rate_is_ms = 2000; //your own refresh rate in milliseconds

cpu.clear(); // Clear all the data
chart.add_unaware_timestamp_collection(cpu, cpu_history, refresh_rate_is_ms);

Please let me know when it's working as expected on your side !

@stsdc
Copy link
Contributor

stsdc commented May 4, 2020

Can confirm that it works. Good job. Thank You πŸ˜„

@lcallarec
Copy link
Owner Author

You're welcome, glad that it works well !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants