Giter VIP home page Giter VIP logo

Comments (3)

lcallarec avatar lcallarec commented on July 21, 2024 1

You're welcome, glad that it works well !

from live-chart.

lcallarec avatar lcallarec commented on July 21, 2024

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 !

from live-chart.

stsdc avatar stsdc commented on July 21, 2024

Can confirm that it works. Good job. Thank You 😄

from live-chart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.