Git Product home page Git Product logo

Comments (2)

williamesp2015 avatar williamesp2015 commented on August 15, 2024

My code is like this but after few seconds chart clearing all the data.

var timestamps = []; // timestamp array
var Chart1data =[];
var cursor = 0; // next refreshing row
var length = 0;
var Counter=0;
var TMPdata1 = 0;
var dataview = new Float32Array(3);
connection.onmessage = function(message)
{
  var buffer = new Uint8Array(message.data);
  TMPdata1 =((buffer[7]<<24)+(buffer[6]<<16)+(buffer[5]<<8)+buffer[4]);
  dataview[0] = Bytes2Float32(TMPdata1);
  timestamps.push(moment());
  Chart1data.push([dataview[0]]);
}

function onRefresh () {
  length =Chart1data.length;
  //messageWindow.value=length;//rows

  Array.prototype.push.apply(
    Chartconfig.data.labels, timestamps.slice(cursor, length)
  );
  for (var i = cursor; i < length; i++) {
    for (var j = 0; j < Chart1data[i].length; j++) {
      Chartconfig.data.datasets[j].data.push(Chart1data[i][j]);
    }
  }
  cursor = length;
}

from chartjs-plugin-streaming.

nagix avatar nagix commented on August 15, 2024

Use the chart reference that is passed as an argument of the onRefresh function.

function onRefresh (chart) {
  length = Chart1data.length;
  //messageWindow.value=length;//rows

  Array.prototype.push.apply(
    chart.data.labels, timestamps.slice(cursor, length)
  );
  for (var i = cursor; i < length; i++) {
    for (var j = 0; j < Chart1data[i].length; j++) {
      chart.data.datasets[j].data.push(Chart1data[i][j]);
    }
  }
  cursor = length;
}

See the working code: https://jsfiddle.net/nagix/6fdLohyu/

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.