Git Product home page Git Product logo

Comments (5)

nagix avatar nagix commented on July 16, 2024

Is this a time-series dataset? Is the value field in child nodes of transactions updated periodically but they don't contain timestamps?

As the onRefresh callback in this plugin only allows pull-based ingestion but Firebase event listeners are push-based, you need a buffer array to connect between them.

To receive data from Firebase:

var buffer = [];

var admin = require("firebase-admin");
var db = admin.database();
var ref = db.ref("<path>");
ref.on("child_changed", function(snapshot) {
  var changedData = snapshot.val();
  buffer.push({
    x: Date.now(),
    y: changedData.value
  });
});

To update the dataset of the chart:

onRefresh: function(chart) {
  Array.prototype.push.apply(chart.data.datasets[0].data, buffer);
  buffer = [];
}

from chartjs-plugin-streaming.

nam1665 avatar nam1665 commented on July 16, 2024

Hi @nagix, I've tried your code but it doesn't work.
"Uncaught TypeError: buffer.append is not a function"

from chartjs-plugin-streaming.

nagix avatar nagix commented on July 16, 2024

Sorry, use buffer.push instead of buffer.append.

from chartjs-plugin-streaming.

nagix avatar nagix commented on July 16, 2024

v1.7.0 supports the push based data feed. You can rewrite the code above without onRefresh as follows:

var myChart = new Chart(ctx, config);

var admin = require("firebase-admin");
var db = admin.database();
var ref = db.ref("<path>");
ref.on("child_changed", function(snapshot) {
  var changedData = snapshot.val();
  myChart.data.datasets[0].data.push({
    x: Date.now(),
    y: changedData.value
  });
  myChart.update({
    preservation: true
  });
});

from chartjs-plugin-streaming.

nagix avatar nagix commented on July 16, 2024

Closing as answered.

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.