-
Notifications
You must be signed in to change notification settings - Fork 16
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
Comments
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 ! |
Can confirm that it works. Good job. Thank You π |
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
Works like a charm ποΈ
![Screen record from 2020-04-09 23 05 43](https://user-images.githubusercontent.com/6031763/78941130-5ca2d300-7ab7-11ea-95d0-1de273fb9c28.gif)
Built in conversion to a
TimestampedValue
would be awesome π€.
Originally posted by @stsdc in #8 (comment)
The text was updated successfully, but these errors were encountered: