Search Unity

Data visualization Unity

Discussion in 'Getting Started' started by StephanUMC, Sep 11, 2017.

  1. StephanUMC

    StephanUMC

    Joined:
    Sep 11, 2017
    Posts:
    12
    I have some Matlab data (x and y coordinates, ie. 2d data) which I would like to stream from Matlab on one computer to Unity on another pc. I'd like Unity to create and visualize a graph of this data 'real-time', eventually for visualization in the HoloLens. Im quite new to Unity and C# but Im wondering if anyone can give me some tips on how to read data from the stream and plot this in realtime. Ive read about the linerenderer and GI options, however I cant find a tutorial on updating the graph real-time with new incoming data from a network stream. In Matlab I created a tcpipserver to stream a dataset and in Visual Studio Ive got a client. Im stuck at creating a clienthandler and visualizing the data (in real-time.)
    -What data format would be most convenient (string, array, matrix....)?
    -How to visualize x,y-data points from Matlab in C# as a graph / plot? (scaling?)
    -How to update the graph real-time, moving the graph to the left replacing old datapoints with new incoming datapoints?

    Thanks in advance
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Sounds like an interesting project.

    For the graph, you might want to study the options available in the asset store. Of course anything you find there, you could do yourself if you had the time and expertise — but it's not exactly easy; Unity's not really designed for this sort of 2D drawing.

    Once you've found a decent graphing/plotting library, then you might ask the author (or post in its forum thread) to ask about how best to update the graph as new data comes in.

    For getting the data across the pipe, use whatever format seems easiest, probably on the Matlab side. In C#, you can easily parse the data in string or binary form.

    Good luck!
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Particle systems are another great way to visualize data.
     
  4. StephanUMC

    StephanUMC

    Joined:
    Sep 11, 2017
    Posts:
    12
    Thanks for the reaction. Do you know some tutorials to use particle systems for visualization of data?
     
  5. StephanUMC

    StephanUMC

    Joined:
    Sep 11, 2017
    Posts:
    12
    Thanks! I have already searched for some options in the asset store, but all the option are quite expensive. Maybe you know some free options? Thanks in advance

    Gr
     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    No, you probably know more about what's available there now than I do.

    So if time is less valuable than money, I guess you'll have to do it yourself.

    What kind of plots are we talking about here? A scatter plot? In that case I guess you could do this with a Sprite for each point. Here's a rough outline of how I would approach it:
    1. Create a sprite that is just a little circle or "x" or whatever you want your points to look like.
    2. Write a script that keeps a big List<GameObject> of these.
    3. In that script, write a "Shift" function that moves all of its sprites over by one column width, and deletes (and removes from its list) any that go out of bounds on the left. (Note: deleting these objects is not the most efficient thing you could do, but it's the simplest and almost certainly fine in this case.)
    4. Also add a "AddPoints" function that takes, say, a List<float> of new values, and creates a new sprite for each one, positioning them on the right and adding them to its list of sprites.
    5. Test this initially by, say, adding a handful of random points every second (via the Update method).
    6. Finally, connect it to a socket to get your real data from Matlab.
    If you want something like a bar chart, the solution would be similar, except that drawing bars is a bit harder — in that case, instead of using Sprites, I'd probably recommend you do it all in a Canvas using an Image for each one.

    In fact, come to think of it, you could a scatter plot on a Canvas too, just using an Image (or RawImage) for each point. This has the advantage of playing more easily with any Text objects you add for axis labels, etc. The disadvantage is that positioning UI elements from code is a little trickier (but certainly doable).

    Let us know if this approach resonates with you, go through the relevant (Sprite or UI) tutorials, and then post back when you get stuck.

    HTH,
    - Joe
     
  7. StephanUMC

    StephanUMC

    Joined:
    Sep 11, 2017
    Posts:
    12
    I'm still trying to get my xyplot working. I am now using the GPU Graph asset (https://www.assetstore.unity3d.com/en/#!/content/72998) for my problem. I've got a .txt data file which I want to import in Unity and plot with the GPU Graph asset. Is there anyone who can help me with this?
     
  8. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I would expect that the author could. The support link on the app store page is http://grujic.ca/ (and I notice a "Support" button near the top of that page).

    Just keep in mind that it's a free asset — he's under no moral or legal obligation to put a lot of time into helping you. But hopefully he can at least give you a nudge in the right direction.
     
  9. popuz

    popuz

    Joined:
    Nov 11, 2016
    Posts:
    2