Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question - How to plot a live data stream #39

Closed
alextran1502 opened this issue Feb 28, 2020 · 5 comments
Closed

Question - How to plot a live data stream #39

alextran1502 opened this issue Feb 28, 2020 · 5 comments
Assignees
Labels

Comments

@alextran1502
Copy link

Hello,

First of all, thank you for your wonderful job. This is a very good library.

I am trying to graph a stream of data, can you help to point me in the right direction.

Thanks

@kroitor kroitor self-assigned this Feb 28, 2020
@kroitor
Copy link
Owner

kroitor commented Feb 28, 2020

Hi! What's your programming language?

@alextran1502
Copy link
Author

hello @kroitor I am using Javascript

@kroitor
Copy link
Owner

kroitor commented Feb 28, 2020

@alextran1502 assuming you can read the data points from your stream, you can add them to the set of most recent maxLength elements in your array of data upon reading, and then redraw the chart using the most recent elements. In the simplest form it would look like:

const maxLength = 80
const numbers = []
while (true) {
    const number = readFromStream () // your reading logic here
    if (numbers.length >= maxLength) {
        numbers.shift ()
    }
    numbers.push (number)
    console.log (plot (numbers))
}

Let me know if that does not answer the question. Feel free to reopen this if needed or just ask further questions, if any.

@kroitor kroitor closed this as completed Feb 28, 2020
@NightMachinery
Copy link

@kroitor commented on Feb 28, 2020, 10:13 AM GMT+3:30:

@alextran1502 assuming you can read the data points from your stream, you can add them to the set of most recent maxLength elements in your array of data upon reading, and then redraw the chart using the most recent elements. In the simplest form it would look like:

const maxLength = 80
const numbers = []
while (true) {
    const number = readFromStream () // your reading logic here
    if (numbers.length >= maxLength) {
        numbers.shift ()
    }
    numbers.push (number)
    console.log (plot (numbers))
}

Let me know if that does not answer the question. Feel free to reopen this if needed or just ask further questions, if any.

I want to just plot the streaming data (each new line being the updated value) from stdin. How do I do that?

@kroitor
Copy link
Owner

kroitor commented Oct 26, 2020

@NightMachinary you could have the chat in a separate blessed window and redraw it when your data changes. In other words, you need to locate your chart in your output and redraw it, by overwriting it.

@kroitor kroitor mentioned this issue Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants