How can I make a graph?

I want to give a swing application x and y parameters and it should then draw a graph for me.
x and only be positiv and y can be both positiv and negativ.
I only give x1, y1, x2, y2, x3, y3, etc and it should draw a graph with the given parameter.
is this possible?`
and is there any finished code?

what I already have is this code but here he draws the function x?, but how can I cange it that he only draws the coordinates i give him x1, y1, x2, y2, x3, y3, etc?
// GraphDemo.java
import java.awt.*;
import javax.swing.*;
public class GraphDemo extends JFrame {
GraphDemo()
// super("Resize me!");
this.setTitle("Frame Title");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(new GraphPane());
setSize(400,400);
setVisible(true);
public static void main(String[] args) {
new GraphDemo();
class GraphPane extends JPanel
final int margin = 8;
public void paintComponent(Graphics g)
Dimension d = getSize();
Rectangle r = new
Rectangle(margin,margin,d.width-margin*2,d.height-margin*2);
// background color
g.setColor(new Color(255,255,255));
g.fillRect(0,0,d.width,d.height);
// grid color
g.setColor(Color.lightGray);
drawGrid(g,r,16,16);
// line color
g.setColor(Color.blue);
drawFunction(g,r);
private void drawGrid(Graphics g,Rectangle r,int w, int h)
for(int y = 0;y <= h;y++) {
int gy = ntrp(0,h,r.y,r.height,y);
g.drawLine(r.x,gy,r.width,gy);
for(int x = 0;x <= w;x++) {
int gx = ntrp(0,w,r.x,r.width,x);
g.drawLine(gx,r.y,gx,r.height);
private void drawFunction(Graphics g,Rectangle r)
boolean start = true;
double epsilon = .01;
double xa = -3.0;
double xb = 3.0;
int oldx = 0, oldy = 0;
for(double x = xa;x <= xb; x += epsilon)
// just a picturesque
// sample function
double y = Math.exp(-(x*x));
int gx = ntrp(xa,xb,r.x,r.width,x);
int gy = ntrp(0,1,r.height,r.y,y);
if(!start) {
g.drawLine(oldx,oldy,gx,gy);
oldx = gx;
oldy = gy;
start = false;
// interpolation routine
private int ntrp(double xa,double xb,int ya,int yb, double x)
return (int)((x-xa)/(xb-xa) * (yb-ya)) + ya;

Similar Messages

  • How can i make a graph y is unmber pasing from UDP port,x is the time stamp.and in the same time this graph can display several numbers to compare.

    how can i make a graph
    y is number(the blue wire)pasing from UDP port,
    x is the time stamp.
    plus in the same time this graph can display several differenr numbers to compare.

  • How can I make a graph using Xcode?

    Hi,
    I'd like to make a graph using Xcode 3.2.5 on an iMac 2009 with Mac OS X 10.6.7. I'm reading temperatures through the serial port (using an USB-serial cable) and I want to show how the temperature increases or decreases along the time. Can anyone help me?
    Thanks.

    history of this question is found here!
    Message Edited by GerdW on 11-26-2007 04:09 PM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • How can I make waveform graph and/or excel file with two different dynamic DBL values?

    As the question describes, I have two dbl sources from a load cell and linear actuator (from firgelli). I want to make a load/displacement curve from the force readings from the load cell and the displacement readings from the linear actuator. The load cell outputs an analog signal that can be acquired by a DAQ and the actuator comes in with a board and VI program to control the speed and measure the displacement of the actuator to a sample rate of my choosing. Is there a way that I can make a VI where it continues to collect data and construct the graph I'm looking for?
    Solved!
    Go to Solution.

    A couple points about your application:
    1.  Synchronization.  Since you're ultimate goal is a stress/strain curve, it is vital that your force and displacement data be synchronized appropriately.  If your sampling is beyond a few times a second, this is not really possible without some form of hardware synchronization via either a trigger and/or sample clock.  Two NI DAQ boards can be synchronized this way easily, but it seems you're using 3rd party hardware for one of these processes.  Would need to know more about that board to know what options you have.  You could specify what your resolution is in distance, and how fast the article will be moving, to get an idea of how fast to acquire, and how well you'll need to synchronize the data.  Another option, since it appears each data stream will be sampled on a hardware-timed sample clock, they will be offset in time, but not skewed during the acquisition.  You may be able to identify a feature in the data set common to each and use that to remove the timing offset after the process is completed.
    2.  Display.  To display data during the acquisition process, I usually recommend at least one display that plots vs. time.  Much easier to spot irregularities with the acquisition process that way.  However, if you'd like to also plot force vs. displacement, you can use an XY Graph to plot parametrically. For Example, in your case you would use the Displacement data as the X coordinates, and the Force data as the Y coordinates.
    3.  Saving data to file.  I would recommend using the Save to Spreadsheet File.vi (File IO pallette) to save your data.  If you use a comma as the delimiter, and save the file with a *.csv extension, you will have a file that is easily read into excel.  The standard tab-delimited spreadsheet file is also fine, it will just require an extra step to read it into excel to specify to excel what the delimiter is.
    4.  Batch vs. Real-Time Recording (Data File).  If your process is short (< 30 sec) you may be better off acquiring the data, Storing it locally to the VI (Array - usually maintained in a shift register), and then writing the file with a header (acquisition parameters, test article information, data column headers) and the data all at once in batch mode to the file after the process is finished.  If, however, it is longer than that you would be better off starting a data file with a header and appending the data to the file as you go, so that if something happens during your test, you at least have data up to that point.
    Hope this Helps,
    Kurt

  • HT202060 How can I make Activity Monitor show one graph instead of four for MacBook Air?

    How can I make Activity Monitor show one graph instead of four for MacBook Air?

    Learn about OS X: Activity Monitor shows one CPU Usage graph on systems with more than four cores
    Copied and pasted from top of the page.

  • How can i make Trend lines in numers for iPad

    Does numbers support trend lines? How can i make them?
    Thank you in advance

    Numbers on ipad does not give you the option of adding trend lines to your graphs at this time.
    Jason

  • How can I make grid lines in ICAL darker?

    How can I make the grid lines darker in I CAL ?

    Numbers on ipad does not give you the option of adding trend lines to your graphs at this time.
    Jason

  • How can I make sure that in RAM our sql server is not facing any mermory crunch issue?

    The SQL server process always show RAM is highly used while its a default behaviour of sql server.
    How can I make sure that in RAM our sql server is not facing any mermory crunch issue?
    Thanks

    The SQL server process always show RAM is highly used while its a default behaviour of sql server.
    How can I make sure that in RAM our sql server is not facing any mermory crunch issue?
    Thanks
    The best way to make sure you are not facing memory pressure is to use perfmon counters and monitor various memory counters
    For SQL Server 2005 - 2008 r2 use below counters
    SQLServer:Buffer Manager--Buffer Cache hit ratio(BCHR): IIf your BCHR is high 90 to 100 Then it points to fact that You don't have memory pressure. Keep in mind that suppose somebody runs a query which request large amount of pages in that
    case momentarily BCHR might come down to 60 or 70 may be less but that does not means it is a memory pressure it means your query requires large memory and will take it. After that query completes you will see BCHR risiing again
    SQLServer:Buffer Manager--Page Life Expectancy(PLE): PLE shows for how long page remain in buffer pool. The longer it stays the better it is. Its common misconception to take 300 as a baseline for PLE.   But it is not,I read it from
    Jonathan Kehayias book( troubleshooting SQL Server) that this value was baseline when SQL Server was of 2000 version and max RAM one could see was from 4-6 G. Now with 200G or RAM coming into picture this value is not correct. He also gave the formula( tentative)
    how to calculate it. Take the base counter value of 300 presented by most resources, and then determine a multiple of this value based on the configured buffer cache size, which is the 'max server memory' sp_ configure option in SQL Server, divided by 4 GB.
      So, for a server with 32 GB allocated to the buffer pool, the PLE value should be at least (32/4)*300 = 2400. So far this has done good to me so I would recommend you to use it.  
    SQLServer:Buffer Manager--CheckpointPages/sec: Checkpoint pages /sec counter is important to know about memory pressure because if buffer cache is low then lots of new pages needs to be brought into and flushed out from buffer pool, 
    due to load checkpoint's work will increase and will start flushing out dirty pages very frequently. If this counter is high then your SQL Server buffer pool is not able to cope up with requests coming and we need to increase it by increasing buffer pool memory
    or by increasing physical RAM and then making adequate changes in Buffer pool size. Technically this value should be low if you are looking at line graph in perfmon this value should always touch base for stable system.  
    SQLServer:Buffer Manager--Freepages: This value should not be less you always want to see high value for it.  
    SQLServer:Memory Manager--Memory Grants Pending: If you see
    memory grants pending in buffer pool your server is facing SQL Server memory crunch and increasing memory would be a good idea. For memory grants please read this article: 
    SQLServer:memory Manager--Target Server Memory: This is amount of memory SQL Server is trying to acquire.
    SQLServer:memory Manager--Total Server memory This is current memory SQL Server has acquired.
       8.  Free List Stalls/sec – Number of requests per second that had to wait for a free page
       9. Free Pages – Total number of pages on all free lists (free lists track all of the pages in the buffer pool that are not currently allocate to a data page, and are therefore available for usage immediately)
    NOTE: If you have NUMA system don't use PLE to monitor memory condition it wont give correct value
    From 2012 Onwards
    Memory management has become easy from 2012 onwards as
    Max server memory also allocated memory for requests which require memory >8KB
    SQLServer:Memory Manager:Free Memory (KB)
    SQLServer:Memory Manager:Target Server Memory (KB)
    SQLServer:Memory Manager:Total Server Memory (KB)
    For NUMA system its also wort monitoring each node.
    Object - SQLServer:Memory Node:Total Node Memory
      (KB)
    Object - SQLServer:Memory Node:Target Node Memory
      (KB)
    Object - SQLServer:Memory Node:Free Node Memory
      (KB)
    Ideally if target server memory is less than or equal to total server memory there wont be memory pressure if target is > total it does not always means its memory pressure
    BCHR would also give you good idea about memory pressure
    If memory grants pending is frequently non zero there is memory pressure
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Wiki Article
    MVP

  • How can I make the Thumpnail  visible in WIN Explorer?

    My OS is Windows8/64.
    My product is PSE11.
    How can I make the Thumpnail ( Preview ) visible in Explorer ?
    Mein OS ist Windows8/64.
    Mein Produkt ist PSE11.
    Wie kann ich die Thumpnail (Vorschau) im Explorer sichtbar machen?

    Right mouse on the graph and select common plots. Under there you can select how you want to display your information. After selecting the display with points, you can go further down the list to Point Style to choose circles,squares etc....

  • I've been trying to make an account with iTunes n everytime I get to the part of the credit card that's as far as I get because I dnt have one, how can I make an iTunes account without a credit card??

    I've been trying to make an account with iTunes n everytime I get to the part of the credit card that's as far as I get because I dnt have one, how can I make an iTunes account without a credit card??

    Where are you located?
    Just go and buy an iTunes gift card at any store in your country.
    Then follow all the steps you did, but when it asks you for the credit card number, there shoujld be a GIFT CARD option which will let you load your account witht eh funds form the gift card without providing a credit/debit card #.

  • How can i make an iTunes store acount without a credit card?

    how can i make an iTunes store acount without a credit card?
    im israeli and the israel store is only the app store.
    i want to get stuff for free without a credit card.
    help?!?

    Just go get a prepaid Visa or something. Put a small amount of money on it and then use that to open an account. If that doesnt work just call them. Contacting Apple for Support and Service 1 800 275-2273

  • HT1918 how can i make an apple id account without a credit card?

    how can i make an apple id account ? it says i need a credit card but i dont have one how can i get passed this?

    Download a free app, create a new apple id account and click none when it says to fill in credit card information.

  • How can I make mac except capture from my canon xlh1?

    How can I make my imac recognize my canon XL1 Camcorder in Final Cut Express

    Assume you are connected by Firewire, and that FCE has Import in some menu? Also check FCE Forum https://discussions.apple.com/community/professional_applications/final_cut_expr ess_hd?view=discussions.

  • TS3988 When I try and log into the icloud, I get a message that my Apple ID is valid but not an icloud account. How can i make it one?

    Whin I try and long into the icloud, I get a message that my Apple ID is valid, but the it is not an icloud account, how can I make it one?

    To use iCloud on a PC, you must first set it up using a device with iOS5 or a Mac with OS X Lion.

  • I synced two of my email accounts via gmail's POP3 thing. But now my iphone's gmail inbox shows a random selection of emails (not most recent ones that are in my inbox). How can I make my iphone inbox match what I see when I log on using a PC?

    I synced two of my email accounts via gmail's POP3 capabilities. But now my iphone's gmail inbox only shows a random selection of emails (i.e. right now it is May 31, 2013 but the emails in my inbox are a couple from Nov 12, a few from Oct 12, and then some way older than that and so on.When I log into my gmail from a computer, I see all my emails in the logical, standard order. How can I make my iphone inbox match what I see when I log on using a PC?

    If you're trying to decide between using POP and IMAP, we encourage you to use IMAP.
    Unlike POP, IMAP offers two-way communication between your web Gmail and your email client. This means when you log in to Gmail using a web browser, actions you perform on email clients and mobile devices (ex: putting mail in a 'work' folder) will instantly and automatically appear in Gmail (ex: it will already have a 'work' label on that email the next time you sign in).
    IMAP also provides a better method to access your mail from multiple devices. If you check your email at work, on your mobile phone, and again at home, IMAP ensures that new mail is accessible from any device at any given time.
    Finally, IMAP offers a more stable experience overall. Whereas POP is prone to losing messages or downloading the same messages multiple times, IMAP avoids this through two-way syncing capabilities between your mail clients and your web Gmail.
    That is from the page that you linked- does highlighted part of message ring a bell?

Maybe you are looking for

  • Find Index for max value of array

    I can use arrayMax to get the max value for a small array, but I need to get which index the max value is located. That will determine which page the user goes to next. Here is my code: array: <cfset arrAverages[1]="#qryFairness.fairness#"/> <cfset a

  • Can't see photos of iPhoto through my Apple TV after moving the iPhoto library to my Airport Extreme Disk. It keeps "loading user's library" forever...

    Hi there, some days ago I purchased an Airport Extreme router with disk to move my iphoto library there and free space of my crowded macbook pro. Everything was working well (iphoto takes a little bit longer to start and quit) but now I can't see my

  • Credit check in sales order

    Hi all, Credit limi check at sales order is working fine, while i am creating a sales order it is giving popup if limit is high then system is giving error message and it is not allowing to save the document. If i save with less quantity and again VA

  • How to eliminate 'recovered messages" in I-Mail

    How does one get rid of the "Recovered Messages" and/or the folders on "ON MY MAC?"  It is the same message that has been replicated over and over.  The message did contain large files attached to the original message. Thank you, Raymond from *******

  • Tutorials about WebServices and Java

    I am looking for general info on how to use WebServices in Java. Has anybody have sample Code? I want to implement a WebService that sends large amounts of data to the client. Can a WebService send complex Objects to the client? thx