3

Is anyone aware of a tutorial or an example that will allow me to do the following: I am inserting live data into mongodb, and would like to visualize it live as a horizon chart by using cubism.js. The visualization should happen as the data is inserted into the database.

The end result will be a webpage where the horizon chart is continuously updated (without reloading the page), similarly to the example at the top of http://square.github.com/cubism/

This question: Using Other Data Sources for cubism.js Is the closest I found to explaining how to achieve this, but I was wondering if there's already a cubism datasource for mongodb available somewhere.

Thanks!

Community
  • 1
  • 1
user1094206
  • 920
  • 1
  • 12
  • 24

2 Answers2

4

You might be better off just using Cube:

https://github.com/square/cube

Cube is a Node.js server, that utilises a MongoDB backend and is designed to store time-series events, and generate metrics.

It's actually written by the same people who wrote Cubism.js - originally Cubism.js was just part of Cube, but they split it off into a separate library.

So you just need to pass your live data to the Cube server, which will insert it into MongoDB - then you can just write a Cubism.js page that will pull live data from Cube - there's already an in-built context in Cubism.js to do this.

If you provide some more details on the live-data you're trying to graph, and what form it is, we can probably give you more specific advice as well.

Cheers, Victor

victorhooi
  • 16,775
  • 22
  • 90
  • 113
  • 1
    Hi Victor, thanks for mentioning Cube. I'm familiar with it, but it seems to restrictive to use it directly. We are dumping real time, time-series data into a mongodb and I'm trying to set up a very simple visualization that will allow us to see roughly what's going on. I think I'll just try to implement a querier that will keep polling the db every few seconds. – user1094206 Apr 04 '13 at 13:58
  • 1
    @user1094206 Hmm, fair enough - is there a specific reason that Cube doesn't fit your needs? The reason I ask is because the project is active, so if there's something missing, they may be able to help you. Also, if you do want to use your existing backend - you can just write a custom Cubism.js context, like I mentioned above that will map to your data. How is the data stored in MongoDB? – victorhooi Apr 05 '13 at 02:27
2

Cubism on the browser will have a socket open, connected to a server. The server itself will have to poll mongo, then send a message to all its listening sockets. Commonly, node.js is used for the server, using the socket.io package to handle sockets. Look into that for your server-side. It has great support for sockets and polling mongo.

000
  • 26,951
  • 10
  • 71
  • 101