Git Product home page Git Product logo

Comments (3)

nagix avatar nagix commented on July 16, 2024

Is the code below useful for you? inputMessage() is a callback function which can be called more frequently than onRefresh() and receives a timestamp and an array of values. refresh() is to be set to the options.plugins.streaming.onRefresh option and updates data from the previous refresh.

var timestamps = []; // timestamp array
var data = []; // two dimensional array (data[row][column])
var cursor = 0; // next refreshing row

// receive data from a client
function inputMessage(unix_timestamp, values) {
  timestamps.push(unix_timestamp);
  data.push(values);
}

// refresh function to be set to options.plugins.streaming.onRefresh option 
function refresh(chart) {
  length = data.length;
  Array.prototype.push.apply(
    chart.data.labels, timestamps.slice(cursor, length)
  );
  for (var i = cursor; i < length; i++) {
    for (var j = 0; j < data[i].length; j++) {
      chart.data.datasets[j].data.push(data[i][j]);
    }
  }
  cursor = length;
}

from chartjs-plugin-streaming.

williamesp2015 avatar williamesp2015 commented on July 16, 2024

Thanks. It would be very nice if you add an full example of a fast line chart. I see some errors in the code.

from chartjs-plugin-streaming.

nagix avatar nagix commented on July 16, 2024

I have fixed the code above and created a working example: https://jsfiddle.net/nagix/pfgr928v/.

from chartjs-plugin-streaming.

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.