Updating A Graph

Hey, i need to make a graph in a JFrame that will update every second from information stored in an array. I've been scouring old forum posts and nothing's really helping. The problem is though, that the graph is part of a program that must also be entirely usable when the graph is updating. Because of this, I dont really know which is the best way to go about making the graph. I've tried doing things with Timer and it was nothing but trouble. I don't want someone to write this for me, I just need some advice and a starting point.
thanx
cha_cha_

try this sample :
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.math.*;
import java.util.*;
import java.applet.*;
public class ecg extends JFrame
     myView  view = new myView();
     Vector  vr   = new Vector();
     data    tread;
public ecg() 
     setBounds(3,10,625,350);
     addWindowListener(new WindowAdapter()
    {     public void windowClosing(WindowEvent ev)
          {     dispose();
               tread.destroy();
               System.exit(0);}});
     getContentPane().add(view);
     getContentPane().setLayout(null);
     tread = new data(vr);
     setVisible(true);
     while (true)
          try
               view.move_1();
               repaint();
               Thread.sleep(100);
          } catch (InterruptedException e) {}
public class myView extends JComponent  
     BufferedImage I;
     Graphics2D G;
     Point p1;
     Point p2;
     int   width   = 600;  
     int   hight   = 301;
     int   point_s = 4;
     Color bcolor  = new Color(220,180,160);
public myView()
     setBackground(bcolor);
     setBounds(10,10,width,hight);       
     I  = new BufferedImage(width,hight,BufferedImage.TYPE_INT_ARGB);     
     G  = I.createGraphics();
     G.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);          
     clear(0,width);
public void move_1()
     if (vr.size() < 2) return;     
     G.drawImage(I,0,0,width-point_s,hight,point_s,0,width,hight,null);
     clear(width-point_s,point_s);
     p1 = (Point)vr.get(0);
     p2 = (Point)vr.get(1);
     G.setColor(Color.darkGray);     
     G.drawLine(width-point_s-1,p1.y+hight/2,width-1,p2.y+hight/2);
     vr.remove(0);
public void clear(int x, int w)
     G.setColor(bcolor);
     G.fillRect(x,0,w,hight);
     G.setColor(Color.lightGray);
     for (int y=0; y < 11; y++) G.fillRect(x,y*30,w,1);
public void paintComponent(Graphics g)
     super.paintComponent(g);
     g.drawImage(I,0,0,null);
public class data extends Thread
      Vector dv;
public data(Vector v)
     super();
     dv = v;
     this.start();
public void run()
     while (true)
          try
               while (dv.size() < 240)
                    int p = (int)(Math.random() * 260);
                    dv.add(new Point(0,p-130));
               Thread.sleep(2000);
          } catch (InterruptedException e) {}
public static void main (String[] args) 
     new ecg();
}      Noah
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.math.*;
import java.util.*;
import java.applet.*;
public class ecg extends JFrame
     myView view = new myView();
     Vector vr = new Vector();
     data tread;
public ecg()
     setBounds(3,10,625,350);
     addWindowListener(new WindowAdapter()
{     public void windowClosing(WindowEvent ev)
          {     dispose();
               tread.destroy();
               System.exit(0);}});
     getContentPane().add(view);
     getContentPane().setLayout(null);
     tread = new data(vr);
     setVisible(true);
     while (true)
          try
               view.move_1();
               repaint();
               Thread.sleep(100);
          } catch (InterruptedException e) {}
public class myView extends JComponent
     BufferedImage I;
     Graphics2D G;
     Point p1;
     Point p2;
     int width = 600;
     int hight = 301;
     int point_s = 4;
     Color bcolor = new Color(220,180,160);
public myView()
     setBackground(bcolor);
     setBounds(10,10,width,hight);
     I = new BufferedImage(width,hight,BufferedImage.TYPE_INT_ARGB);     
     G = I.createGraphics();
     G.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);          
     clear(0,width);
public void move_1()
     if (vr.size() < 2) return;     
     G.drawImage(I,0,0,width-point_s,hight,point_s,0,width,hight,null);
     clear(width-point_s,point_s);
     p1 = (Point)vr.get(0);
     p2 = (Point)vr.get(1);
     G.setColor(Color.darkGray);     
     G.drawLine(width-point_s-1,p1.y+hight/2,width-1,p2.y+hight/2);
     vr.remove(0);
public void clear(int x, int w)
     G.setColor(bcolor);
     G.fillRect(x,0,w,hight);
     G.setColor(Color.lightGray);
     for (int y=0; y < 11; y++) G.fillRect(x,y*30,w,1);
public void paintComponent(Graphics g)
     super.paintComponent(g);
     g.drawImage(I,0,0,null);
public class data extends Thread
     Vector dv;
public data(Vector v)
     super();
     dv = v;
     this.start();
public void run()
     while (true)
          try
               while (dv.size() < 240)
                    int p = (int)(Math.random() * 260);
                    dv.add(new Point(0,p-130));
               Thread.sleep(2000);
          } catch (InterruptedException e) {}
public static void main (String[] args)
     new ecg();

Similar Messages

  • Updating xy graph with the last point different

    I want to display a simulation of the path of a rolling ball as updating xy graph.
    The actual last point of the plot should be different from the older points, I imagine e.g.a thick circle.
    The coordinates of the points I hold in two arrays, so I need a xy graph,
    when I used xy chart buffer to get un updating graph all points of the
    plot are displayed in the same way, stars, circles and so on.
    I

    Ok, so the solution is coming from what you've just said. One plot for the old positions I assume you want to display a certain number of points... e.g. the last 10positions and one plot for the current ball position.
    Tell me if this is ok...
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
    Attachments:
    ball.vi ‏50 KB

  • How can you rotate the labels on the category axis of a graph in Illustrator and have it stay the same when updating the graph data?

    I am needing to create a line graph with dates consisting of MM/DD/YY along the category axis. I would like to rotate the labels 45 degrees and have them stay when I update the graph. I have read about manually doing it, I even made an action to make it faster, but it still seems inefficient. Is there a setting that I could use to automatically create my labels as rotated? Thanks.

    Hi Gravy Train,
    I'm curious about why you are using 2 loops.   You mentioned one is for monitoring and one is for DAQ....what do you mean by that?   What is the overall goal of this piece of code.   Also, I noticed that you are not closing the task.   Since this is just a subset, I realize you could be closing it in your actual code, but just in case you're not.....it is very important that you close all tasks when you are down acquiring data.
    Best Regards,
    Starla T  

  • Trouble getting a subvi to update a graph in real-time on the front panel

    Hi All,
    First post here, so play nice =). I am trying to update a graph on the front panel from within one of my subvis, however it does not update it in real-time. It will only show the completed graph after the subvi finishes running. I have tried to use references/property nodes and I have also tried using my chart as a global variable, but neither of those methods have worked (I am probably doing it wrong). Can anyone provide a detailed walk-through of how to do this using either one of those methods? Or perhaps even a different method?

    ModusPwnens wrote:
    This is how you do it, right?:
    Try this for a quick demo of the reference method:
    Create a VI as shown in the image.
    Select only the while loop and do "edit...create subVI" (as shown). (you will get a subVI that contains the needed connectors and is alread wired to the reference)
    Run the main VI, and the chart will update every 200ms.
    Note that this is only a draft and many things are missing. (For example, the subVI cannot be stopped at the moment. Also, you want a graph, and not a chart.)
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    updateViaSub.PNG ‏32 KB

  • Can I use a script to update a graph.

    We have several charts(graphs) within an InDesign document. We update the graph manually using a tab delimited text file. Is there a way to script this? I've scripted the InDesign document to update the links and verify the age of links but I've had quite a time to understand objects within Illustrator. I tried actions but the actions ignore graph items in my trial. I've even tried VB.NET but I don't understand what the data source for the graph is.
    Thank you for any help.

    To my knowledge to only way in which you can change an Illustrator graphs data is to use datasets. You can import new data then update. You will need to work with XML thou… Have you not taken a look at marc's pie-chart script…
    http://indiscripts.com/

  • Updating pie graph  with the pivot table data.

    Hi:
    I have two components, the first is a pivot table and second
    of them is the pie graph, the two components were created in JDeveloper 11g
    on the same page through the same view object, this view object was created through
    a query.
    I need to update the pie graph through the pivot table data.
    ie, according to the data containing on the pivot table, to update the pie graph.

    Hi,
    BPM can be used to validate and update tables.  You can have a transformation step in BPM to validate, and either a JDBC or RFC adapter to update XI table...depending on if the table is an ABAP table or table create outside of ABAP using the vendor's dba tools.
    As for sending file based on counter or timestamp in the name, you can develop a simple adapter user-module using java which can retrieve the file name(s) being processed.  If the name satisfy the rules you have, then proceed, or else terminate the processing in the adapter.
    Regards,
    Bill

  • How do I manually update a graph/chart

    I have a chart on my front panel in which the data is continuously being changed.  Each loop cycle (few seconds each) I clear the chart history (property node), update the chart data, and then change the Chart range to the range that it previously had.  However every time I do this I can see (for less then half a second) the clear chart and then some segment of the new data before it shows the correct data range that I want.  Is there a way to delay graph from updating until I signal it to update so I do not see the intermediary garbage data?
    Thanks in advance,
    David

    Look for the Defer Panel updates property node.  Set it to True before you do the other properties and False After.
    But if you have the need to set the range back to a value it was before, it sounds like you might have the axes set for autoscaling. ??  You may want to turn that off.
    Message Edited by Ravens Fan on 12-18-2008 01:08 PM
    Attachments:
    Defer.PNG ‏22 KB

  • SubVI - VI Update ? Graph, Intensity graph.

    I have a subVI which calculates data that is to be displayed in an
    intensity graph as it gets updated. I want to display the same
    intensity graph on my main VI to show the progress and update. I've
    tried using global variables, but it doesn't work well. Any suggestions
    Thanks
    Kudos always welcome for helpful posts

    I tried that before. doesnt seem to work. Please see attachment...
    Kudos always welcome for helpful posts
    Attachments:
    main.llb ‏36 KB

  • Displaying seconds updation on graph

    Hi
    all , i would like to display x-axis (time)in seconds.since my programme while loop is repetaing at a duration of 10msec ,but how to show updation in seconds on graph(x-axis).
    Regards
    labview boy
    code attached
    Attachments:
    sine.vi ‏92 KB

    I couldn't open your VI, but to display a graph as time, right click the axis and select "Format & Presicion", then change the format to Absolute Time or Relative Time. That's it. If you're using Absolute Time, you should use Get Date\time in seconds and To DBL and wire the result into the property X-Scale>>Offset & Multiplier>>Offset to set the t0 of your axis to the current time.
    Try to take over the world!

  • Continual graph points updates xy graph

    Hi i was wondering if there was a setting on xy plots so that it would plot all previous points, given a changing value of x and y.
    Sort of like the wave form updates graph, but so that i can use both axises for values, and the x axis doesn't become the ongoing count?
    It may be blatantly simple, but i'm trying to create a graph that will trace a path out with a changing x-y values, but keep a tail behind it of where it has been right back to the first point.
    I also thought it might be possible to store the data in an array and feed an ever enlarging array into the graph but that seems to have out witted me, and i was wondering if there was a simpler method?
    please help!!!

    Found a method that is rather simple.
    If you are generating the points from a changing singular numerical value then by feeding these into an array with cocatulate inputs on, then the values will simply build into two 1d arrays, updating with each new point,
    a picture is attached if anyone has a similar problem.
    - i knew i knew how to do this, it just didn't work the first 3 times.
    John P.
    Attachments:
    solution.JPG ‏25 KB

  • Periodically updating a graph from a continually updating array

    I'm back after a few weeks of playing around with LabVIEW to try to fix it myself. I've gotten pretty far, I think, considering I have only myself and the two books "Learning with LabVIEW 7 Express" and "LabVIEW Graphical Programming" to help me!
    My previous post on this subject can be found here, though it is not necessary to read in order to help me with my current problem.
    With this post you will find 3 VI's that I have created, these are:
    "sub-test.vi" is my first attempt at creating a usefull sub-vi. I have documented it and made an icon for it, but all it does is really save me from a few extra blocks in my program.
    "neat but not working.vi" or ex1: I think it looks neat, but it will not work the way I would expect it too.
    "messy and still not working.vi" or ex2: this one looks more messy, uses a for loop instead of a while loop and is not working the way I want it too either.
    What I am trying to do:
    I have incomming serial data tagged with the channel name. I know how to extract the data (16bit unsigned int) from the header and footer using match patterns and type-cast (see sub-test.vi). I now want to "save" the incomming channel data (for simplicity lets assume that I only have one channel, called T1) in an array called T1. Naturally, I need to be relativly sure that my array actually does store my data (coming in at about 2/second). I then want to display that array in a graph at a set interval, say, every 2 seconds for example.
    So far I have been playing around like a blind person on an open field, feeling my way in the dark. I have tried a lot of solutions that seemed like good and logical solutions to me, but they didn't work, so obviously my logic is flawed.
    In Ex1 I tried to time the graphing by placing the graph and array in a sepparate while loop along with a "Wait until next ms multiple". The reading of the serial port is handled in a separate while loop running at max speed to catch all incomming data. It doesn't work the way I want it too.
    In Ex2 I tried to achieve my goal with another tactic. In this I get the graph to display stuff all the time, but I am unable to time the "refresh" of the graph.
    You may notice that I use the "old" serial port VI's (if you take context help on the Serial Port Init VI you will see a note explaining how it has been replaced with VISA VI's in the functions palette.. I have tried to use those, but I find them to be more difficult to set up. That is, I got it up and running and accepting data, but I got some errors and crashes from time to time, so I guess I used them incorrectly. Anyway, what I want to say is that if you feel that I should use the VISA VI's instead, I will need someone to set them up correctly for me the first time so I can see how it should be done.
    Both Greg McKaskle and Brian Powell provided a lot of help in my first thread at the very beginning of my project, and I hope that someone will be just as helpfull this time around!
    I use LabView 7 (the posted VI's from school) and Labview 7 Express on my personal laptop. (what -is- the functional difference between the two? I have not found anything? The only difference beeing that the Express have a watermark on the VI's?
    All the systems use Windows XP
    Attachments:
    Sub-test.vi ‏16 KB
    neat_but_not_working.vi ‏34 KB
    messy_and_still_not_working.vi ‏46 KB

    aha! I thougth that when I used the "counter" to see how many bytes waited for me at the port, then it wouldn't put lots of 0's in my array.
    I guess I could save the incomming stream to a file (that is a requirement, I need to log the data to a file) and then read the port every n'th second so that I know it contains roughly x samples and then parse and display all of that data. If I manually allocate the port-buffer size to hold the expected number of bytes + a marginal, that could work, right? In which case I should use a case structure (if "graph on" is true, then, say, every second, read the port buffer, parse the data into their respective arrays and graph/chart them).
    I don't need to display all the received data, but if I use a chart I don't have to worry about the buffers since my total data ammount (per. chart) will be less than 45000.
    I will look into charts again, I just tested to pass arrays to a chart, and that works too, with the added benefit that I can, as you say, have a display buffer so that I don't have to worry about that with my arrays. I can pass fixed size arrays to the chart and the chart will keep a (limited) history for me. I think that will work out great. The total number of data points at the end of the 6 hours should be around 43200, menaning I can hold the entire 6 hours in the chart buffer too without it impacting the performance to much.
    So what I need to fix now, regardless, is the "read from port" function so that it does not fill up my array with zeros!
    And I noticed in a test VI that generates 3 constant value arrays and one "random number 0 to 1" array, that if I pass it all to the chart, the data is not displayed as expected. In the included VI, the graph shows 3 straight lines and the random number, while the chart doesnt. In the chart there are no stright lines. Also, the top one in the chart (I have 4 on display, and I run them stacked) has all the lines, while in the other 3 I get one line (channel) just as I wanted. Why is that? I'll look into all the problems myself, but if someone could give a tip that would be great because I am still very much a student and learning by trial and error can be very frustrating.
    Attachments:
    array_and_graph_conondrum.vi ‏48 KB

  • V8.2 "Not Responding" when updating XY Graph Prpoerties

    LabVIEW 8.2 running on Windows XP crashes (slows to mouse clicks then gets reported as "Not Responding") when I try to format the plot properties (color, weight, etc) on a multi-plot XY Graph.

    ST1,
    Could you provide us with some more details so that we can better help you?
    How much data must be graphed to cause the slowdown (both data-points and plots)?
    Does this happen with any multi-plot XY chart or just in one VI?
    Is your XY chart inside a tab control or similar structure?
    Is your computer running low on memory when this happens?
    Regards,
    Simon H
    Applications Engineer
    National Instruments

  • Update multiple graphs at once

    Hi, I have a VI containing multiple graphs (on a page of a tab control, to be precise) like these:
    Now, I'd like when the VI starts to initialize all of these graphs in the same manner:
    Basically, removing all the plot names and making them all not visible.
    Later, as my VI executes, I want to populate each graph with its relevant data and decide programatially on the number of plots in each graph, on the names of the plots etc.
    Now, it is OK to do it like above when one has a few graphs, but I am going to have some 16 of them and it is a real pain to add the wires as in the above screenshot every time I decide to add a graph to the front panel or if I decide some additional initialization is needed.
    Can this be done in some sort of a loop? I visialize some sort of loop going thru all the graphs belonging to some LabView object and somehow setting all those properties, while retaining the ability to reference each individual graph later in the program (by it name).
    Thanks in advance for your help.
    Solved!
    Go to Solution.

    Create an array of references for each of those graphs.  Unlink the property notes from the graph and feed it the array of references from outside the loop.  Now the loop will autoindex over the array and setting the properties on each of those graph references.

  • Problem in Server Admin: cpu and network graphs not updated or empty after lion server update

    Hi!
    Just for archive purpouses because i've already solved that!
    After upgrading from OSX Server 10.7 to 10.7.1 my CPU and Network graphs in Server Admin stop being updated.
    In 24h the graphs where blank (disk usage graph seem to keep working).
    First i read about "what is the application responsible for this"; it's called ServerPerfLog, and you can see if it's running that way:
         # ps ax | grep ServerPerf
    If you don't see anything else than your own "grep", that means that no application is running, no data is being collected.
         41324 s000  R+     0:00.00 grep ServerPerf
    A positive response for this (meaning that the service is running) should be something like that (2 lines: your grep and the service app itself):
         94   ??  Ss     0:04.71 /usr/libexec/ServerPerfLog
         41344 s000  R+     0:00.00 grep ServerPerf
    Later i read about "where is the config file for this service app", and you can find it here:
         /System/Library/LaunchDaemons/com.apple.ServerPerfLog.plist
    If you edit this config file, check that the "Key > Disabled" is set to "False"
         # vi /System/Library/LaunchDaemons/com.apple.ServerPerfLog.plist
            <key>Disabled</key>
            <false/>
    After that, i try to launch the service that updates this graphs again, by hand, performing the following command:
         # sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.ServerPerfLog.plist
    And the service got launch!!! yeeeepa!! i see a first update in graph data.
    Also the "ps" query reply that the service was running!!
    The bad things came a day after, when i saw that the graphs stop again....
    I check if the service was running executing again the "ps" command, and that show me that the service was stopped again; no ServerPerfLog process was running.
    But r e l a x, because the process hang because of a permissions problem.
    You should know, I run "Repair permissions" within "Disk Utilities" over the running system disk, eeee... voila!
    I hope that helps someone to get his fancy graphs back!
    Regards,
    t

    You are God like!!! Wooo hooo! Thanks bud!

  • Graph scale updates on tabs

      We have a program with several tabs, each of which has different graphs and displays.  On one of the tabs is a histogram style bar graph.  We've added annotations to each bar to label each bar with a particular identifier.  The graphs are set to autoscaling, so first we write the data to the graph with a "Value" property node, then read back the graph's YMax value and use that to help calculate where to put each annotation.  (We typically put the annotation above the bar, but have to limit it to less than the YMax value so it stays on the graph.)  Works fine, as long as the graph's tab is displayed.
       So now you're displaying a different tab and put new data into the system.  Then click to the aforementioned tab.  The new data is displayed, and the graph is properly auto-scaled, but the annotations are out of place.  The YMax that was used to calculate their maximum y position was the graph's YMax from the last time it was displayed.
       What appears to be going on is that the graph's display isn't completely updated when LabVIEW knows that the graph isn't visible.  When you later make the graph visible, LabVIEW appears to have instantly autoscaled it correctly, but the YMax value that was available when the annotations were being created isn't the YMax that would be expected from the new data.
       Our work-around is to use the maximum Y value of the data.  For autoscaled graphs, this is usually pretty similar to the YMax of the axis, but not exactly the same.
       Does anyone have any insights or other ideas?  (Synchronous display didn't seem to help.  And we couldn't find any other property nodes that might be relevant.)
    Thanks,
       DaveT
    David Thomson Original Code Consulting
    www.originalcode.com
    National Instruments Alliance Program Member
    Certified LabVIEW Architect
    There are 10 kinds of people: those who understand binary, and those who don't.

    DaveT,
    This may be a complete hack/abomination, but if you are prevented from manipulating your graph if the tab is not visible, you could use an Event Structure and handle the tab's Value Change event.  Update your graph within that event.
    -cb

Maybe you are looking for

  • Questions in upgrading Adobe Reader

    I have to upgrade latest version of Adobe Reader in thousands of PC, by deployment in Group Policy Management, Those PC has different version (e.g. 5.0 to 9.0). The problem is, the new version is deployed and installed, the older version still exist.

  • Macbook Pro 13" Loud Spacebar

    I just bought a new macbook pro 13" and am very happy with it except for the fact that it has a noticeably loud spacebar.  I have been reading a few discussions online about older versions of the macbook pro having this same problem, but I have not c

  • Windows host cannot establish Ethernet link to Arch Router

    This is a weird problem. I have a Windows host about 20 meters away from my Arch Router, the Ethernet cable goes into the wall, with wall sockets, so it's a total of 3 cables (1 in wall, 1 @ router, 1 @ host). I've tested the Ethernet cables with a L

  • Org.w3c.dom.DOMException: NO_MODIFICATION_ALLOWED_ERR

    Hi, I got this error when trying to add new node to Document object      public Document createDomFromXML(String strXmlFile)           throws Exception {           DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();  

  • Adding Show more link in multi select refinement panel

    Hi, Is it possible to add show more link in multi-select refinement panel.In the default refiners, the show more link comes OOB.Is it possible to bring the same logic in multi select refinement panel? Thanks,