Problem displaying a graph

I am trying to display a line graph from a given arrays of integers, which are stores as x and y points consecutively. (ie. int values[] = {x0,y0,x1,y1,etc...})
However, after I compiled and run the code, no graph is displayed. What's wrong?...
import java.awt.*;
import javax.swing.*;
public class GraphicTest extends JPanel
     private int values[]={2,5,6,34,12,28,18,24,22,26,25,16,30,41,34,7,39,18};
     public void paintGraph(Graphics aGraphics, int values[])
          int x = values[0];
          int y = values[1];
          aGraphics.drawRect(x-2,y-2,x+2,y+2);
          for (int i=0; i<values.length; i+=2)
               aGraphics.drawLine(x,y,values,values[i+1]);
               x = values[i];
               y = values[i+1];
               aGraphics.drawRect(x-2,y-2,x+2,y+2);
     public static void main (String args[])
          JFrame frame = new JFrame();
          frame.setLocation(100,100);
          frame.setSize(400,300);
          frame.getContentPane().add(new GraphicTest());
          frame.show();

This is a very nice piece of code, but you do have to call it. Override JPanel's paintComponent method, so that it calls paintGraph(), and your're done.

Similar Messages

  • Problems building a graph using sql SUM

    Hello !
    i'm curently having issues to build a particular graph :
    First, i have a database (moves) which contains 2 columns (timestamp DATETIME, dist NUMERIC), i have no problems to display a graph with these values (even using a time range such 'now','-1 hours', etc.).
    But i'd like to build a graph with for example a 2 hours range which gonna display the sum of the value 'dist' every 30 seconds. So for example, if i have 2 'dist' values (3 and 4) at 0min 30sec, the graph will display 7 and the next value will be the sum of
    the next 30 secondes dist values.
    I tried this :
    curs.execute("SELECT timestamp,SUM(dist) AS dist30 FROM moves WHERE timestamp>datetime('now','-30secondes')"
    curs.execute("SELECT timestamp,dist30 FROM moves WHERE timestamp>datetime('now','-1 hours')"
    But it looks like the column dist30 is not created, and i think this is not gonna work if i want to change the 1 hour range...
    I would like a better "algorythme", the table is filled in an other program, should i directly create a 3  columns table and SUM the dist in dist30 directly ?
    Thanks for your advice !

    Hi Subby,
    Regarding your description, are you trying to rollup the dist column by every 30 seconds in a given 2 hours range? If my understanding I correct, you may reference the below sample. As you didn't post any detail about your function datetime(after the where
    clause), so the sample is just in a usual way.
    CREATE TABLE moves(timestamp DATETIME, dist NUMERIC)
    INSERT INTO moves VALUES('2015-02-13 14:20:01',1)
    INSERT INTO moves VALUES('2015-02-13 14:20:17',2)
    INSERT INTO moves VALUES('2015-02-13 14:20:29',5)
    INSERT INTO moves VALUES('2015-02-13 14:22:37',2)
    INSERT INTO moves VALUES('2015-02-13 14:22:56',5)
    INSERT INTO moves VALUES('2015-02-13 14:27:17',2)
    SELECT timestamp,SUM(dist) AS dist30 FROM(
    SELECT DATEADD(SECOND,DATEPART(SECOND,timestamp)%30*-1,timestamp) AS timestamp,dist FROM moves) AS T --rollup by every 30 seconds
    WHERE timestamp BETWEEN '2015-02-13 13:00:00' AND '2015-02-13 15:00:00' --two hour range
    GROUP BY timestamp
    If you have any question, feel free to let me know.
    Eric Zhang
    TechNet Community Support

  • Problem in reterving graphs

    Hi
    i have to face the problem in reterving or displaying the graph..in a application..and plz help that in Regedit where i should give the path of the graph...
    plz help me in this regard
    thx in advance

    before you start creating the graphics some questions :
    - did you know, that this technique is dead, when you migrate to forms 10g ?
    - is this the first graphics-file you developed?

  • Problem with bar graphs in Crystal Report

    Hi All,
    I am currently working on bar graphs and i am facing problem displaying trend in the graph when there is no data for any particular date.
    My X-axis has date and y-axis has data.
    I want to display all the dates on x-Axis which is selected by the user.
    E.g.  User has selected fromDate and ToDate as 1st Aug to 10th Aug and I have Data as follows
    08/01/2008 abc
    08/03/2008 xyz
    08/05/2008 klm
    Currently my graph just shows data for 1st,3rd and 5th of August.
    I want my Graph to show all the dates from 1stAug to 10thAug on x-axis and it should not only show  data where it is but also a blank where data is not present
    Please help. Thank you.

    Hi Tenzin
    Following are the steps from where you can change the division of the axes:
    Right click on the report.
    Go to 'Chart Expert' -> 'Axes' tab.
    Select the Manual option under 'Number of divisions'.
    Change the settings so that you can get each date on the axis.
    Hope this helps you.
    Please let us know if you have any further queries.
    Regards
    Ashwini Yadav

  • Work book migration problem : error in graph

    Hi all,
    I have a work book ,created in 3.x ...now we are on 7.0 So when iam migrating i got error .
    I have resolved  other errors..but one error is remained , problem with the graph....
    on X axis with values it is showing header row also..how can i avoid header row...? to not display in graph....
    As data table  source controlled by BI  so ia mnotable to maintain range for graph....
    Problem is when it is with out scalling factors it is displaying correctly in graph also..
    When iam selecting option to display scalling factor it is showing header row also in graph... coz of that graph was showing wrong data...
    cal day    Quantity
    above is with out scalling factor display..everything correct
    blank     Quantity
    cal day       KG
    When iam selecting scalling factor sys will add one more row to display... this is the problem sys did not set automaticaly to consider or to leave first 2 rows...
    How can resolve...? In 3.X it is working fine...... (There is no macro )
    Thanks
    BK
    Edited by: BK BI on Jun 8, 2010 8:56 AM

    Hi,
    Go to the workbook in development system. Find out the technical name of the workbook ( in query designer you wil find in properties).
    Copy it and go to the production system. Assign it to the required role you want. It will be visible in the perticular role in production.
    I would still suggest if possible transport the role from dev to prod. (to keep all systems in line with each other)
    Hope this helps.
    Regards,
    Viren

  • Problem with xy-graph program

    HI!
    I have a problem with my program. With this program i want to load a datafile and to display  the data from the file on the xy-graph. i want to display 1,2,3 or 4 graphs on the xy-graph. The problem is, when i want to display only two graphs and i push the "... laden" button, a popup will open and ask me for the 3rd ord 4th graph, but i want only display two graphs.
    The program should display the data, when there is a path added in the path-element (the white,red,blue or grenn one).
    The second problem is, when i start the program and push the "...laden" button and no path added,  a popup will open and aks me for files, but the popup should not open!
    Could somebody help me???
    TNKS
    best regards,
    peter
    Labview 7.1 on Windows 2000
    Attachments:
    program.zip ‏30 KB

    Hi,
    The function you're using to open the file is automatically asking for a file name when you call it with an empty path connected to the file path input.
    So, if you don't want to get the data when the path is empty, you should not call that function.
    I've changed your vi to show you.
    Hope it helps,
    Paulo
    Attachments:
    Vergleich_XY.vi ‏93 KB

  • Displaying Plus Graphs in Viewer

    I trying to display a graph which I've created in Discoverer Plus in the Discoverer Viewer. I was wondering what steps need to be taken to get the graph to display. (which pages and components you had to modify, special way to save the worksheet in Plus, etc.) Any help would be greatly appreciated
    -Thanks
    Andy

    Hello.
    I don't know if this helps, but:
    I believe that, if you create a graph in Desktop, it will NOT show up in the Viewer. Only graphs that are created in Plus show up in Viewer.
    I have noticed problems with workbooks when I open them in desktop--even after creating them in Plus. I am trying to avoid the Desktop version all-together.
    If I were you, I would try to create the workbook from scratch and add a graph in Plus only. Then, check it out in the viewer.
    There are also URL parameters that help with the display. You may want to check the docs.
    Good luck!
    Robin

  • It is possible to display a graph in smartforms

    Hi,
    In report , i am displaying the graph similary i want to   print the graph in smartforms.
    Plz give me details .
    Wht is spf ?
    Regards,
    Rani.

    Hi Rani,
    chech this link..
    http://searchsap.techtarget.com/loginMembersOnly/1,289498,sid21_gci1192768,00.html?NextURL=http%3A//searchsap.techtarget.com/tip/0%2C289483%2Csid21_gci1192768%2C00.html
    Reward points if helpful..
    Regards,
    Goutham.

  • Problem displaying CLOB in text file

    Hello All,
    I have a problem displaying the content from the database in notepad. When I click on a link on my jsf screen, I retrieve the data and display it in notepad.
    I have my text content stored in the database with CLOB datatype. When I look in the database the data looks in the following format:
    ---------STARTS FROM NEXT LINE-------------
    The firm, known for its keen oversight of products, has been the subject of complaints from firms who have had apps blocked from the store. Some developers have complained that the company's rules seem inconsistent.
    Some have found apps blocked after seemingly minor updates, or for having content deemed inappropriate by them. In light of this, and after careful consideration, I believe it is unnecessary to sign this measure at this time.
    Sincerely,
    ABC
    ----------ENDS IN THE PREVIOUS LINE------------
    Now when I display this content onto the notepad, all the spaces and new line characters are lost, and the entire display looks awkward. This is how it looks:
    The firm, known for its keen oversight of products, has been the subject of complaints from firms who have had apps blocked from the store. Some developers have complained that the company's rules seem inconsistent.[]Some have found apps blocked after seemingly minor updates, or for having content deemed inappropriate by them. In light of this, and after careful consideration, I believe it is unnecessary to sign this measure at this time.[]Sincerely,[]ABC
    All the new line characters are lost and it just puts some junk character in place of a new line.
    When I copy the same text onto textpad, everything is alright and it displays exactly the way it is present in the database. I am also open to display the content in html, but in HTML it doesn't even display me the junk character in place of new line. It is just one single string without any line separators.
    I am using the following code to put the content into the text.
    public String writeMessage(){
       OutputStream outStream = null;
       HttpServletResponse response = getServletResponseFromFacesContext();
       Reader data = null;
       Writer writer = null;
       try{
          response.reset();
          response.setContentType("text/plain; charset=UTF-8");
          response.setHeader("Content-Disposition","attachment; filename="+id+"_Message.txt");
          outStream = response.getOutputStream();
          QueryRemote remote = serviceLocator.getQueriessEJB();
          data = remote.retrieveGovernorsVetoMessage(billId);
          writer = new BufferedWriter(new OutputStreamWriter( outStream, "UTF-8" ) );
          int charsRead;
          char[] cbuf = new char[1024];
          while ((charsRead = data.read(cbuf)) != -1) {
             System.out.println(charsRead);
          writer.write(cbuf, 0, charsRead);
          writer.flush();
       }catch(Exception ex){
          ex.printStackTrace();
       }finally{
          //Close outStream, data, writer
          facesContext.responseComplete();
       return null;
    }Any help or hints on resolving this issue would be highly appreciated.
    Thanks.

    The data is imported from a third party application to my database. It doesn't display any newline characters when I view the data.
    But when I do a regular expression search on text pad, I could see that my clob contains \n as the new line character. Is there a way to replace \n with \n\r while writing the data.
    Thanks.

  • My problem is the graphs of my audio recordings in the arrange window are so small it makes accurate editing very difficult.

    My problem is the graphs of my audio recordings in the arrange window are so small it makes accurate editing very difficult.

    Try the waveform zoom slider. Recording louder just to get a better visible waveform would be, well, silly.
    From the manual: (click on links to see pics)
    To change the zoom level using the Waveform Zoom button 
    Click-hold the Waveform Zoom button. A slider appears.
    http://documentation.apple.com/en/logicpro/usermanual/Art/S01/S0185_WaveZoom.png
    Drag the slider. As you do, the waveform shown in all audio regions, and in the Beat Mapping track, is increased or decreased in size.
    http://documentation.apple.com/en/logicpro/usermanual/Art/S09/S0931_CUS_Waveform Zoom2.png 
    Note: This is a purely visual function. The amplitude (level) of the waveform is not affected.
    it's here (scroll 3/4 down):
    http://documentation.apple.com/en/logicpro/usermanual/index.html#chapter=4%26sec tion=6%26tasks=true

  • Problem displaying picture stored in mySQL

    Hi, i just have got problem displaying picture stored in database as BLOB and presented on JSP over servlet. Below is my code i am using to upload file into database, than download it and display again. The result is the picture can not draw inself and there is always only empty picture space on the web page i am displaying. Please help me to find why it is not working, thanx.
    servlet uploading picture to database
                   boolean isMultipart = FileUpload.isMultipartContent(req);
                   DiskFileUpload upload = new DiskFileUpload();
                   List items = upload.parseRequest(req);
                   Hashtable textFields = new Hashtable();
                   byte[] data = new byte[4096];
                   if(isMultipart)
                        Iterator iter = items.iterator();
                        while(iter.hasNext())
                             FileItem item = (FileItem)iter.next();
                             if(item.isFormField())
                                  textFields.put(item.getFieldName(), item.getString());
                             }else{
                                  data = item.get();
                   String sqlStatement = "INSERT INTO cds VALUES('" textFields.get("id")"'," +
                                            "'" textFields.get("album") "','" textFields.get("interpreter") "'," +
                                                      "'" textFields.get("gr1") "','" textFields.get("gr2") "','" textFields.get("price") "')";
                   String sqlStatement2 = "INSERT INTO pics VALUES('" textFields.get("id") "','" data "')";
    servlet to download picture
    String SQL =
         "SELECT Picture " +
         "FROM pics " +
         "WHERE id = '" + request.getParameter("id") + "'";
         ResultSet rs = stmt.executeQuery(SQL);
         rs.next();
         Blob blob = null;
         blob = rs.getBlob(1);
         response.setContentType("image/jpg");
         request.setAttribute("blob", blob);
         System.out.println("just above OutputStream");
         InputStream in = blob.getBinaryStream();
         ServletOutputStream sout = response.getOutputStream();
         int b;
         while ((b = in.read()) != -1) {
         sout.write(b);
         in.close();
         sout.flush();
         sout.close();
    img tag in JSP
    <img src="LoadImageServlet?id=some id>
    plus i am using
    Tomcat 5.0
    mySQL 4.0
    debuging in eclipse
    thanx for help once more, Libor.

    1:
    are there any exceptions throws by the jdbc code
    2:
    is the code in a doGet
    3:
    you should do a if(result.next())
    4:
    Is your mapping code working

  • Display only graph in the Crystal report viewer

    Background:
    We used Crystal Reports ver10 to display various graphs in our ASP.Net 2.0 Web Application (Visual Studio 2005)
    We recently migrated our application to .NET 4.5 and Crystal Reports ver13 (Visual Studio 2012)
    Issue:
    Now, the Crystal Report Viewer control loads the graph inside an <IFRAME> which shows the whole page with the graph placed on the right bottom corner instead of just the graph image as it used to previously.
    I have checked various properties that hides the tree and the toolbar and I am unable to get rid of the whole page.
    Query:
    Is there a way to not display the page and display only the image that contains the graph? OR
    Is there a way to not render the whole <iframe> and just display the graph image inside a <div> as it used to happen before?

    Hi Ludek, thanks for your response. Please refer the screenshots below.
    1) CR ver10 - the graph <img> is simply enclosed inside a div
    2) CR ver13 - the graph <img> is enclosed inside an <iframe>'s body - you can also see the scroll bars and "white-page-background" and "grey space" which I am hoping to hide or disable
    3) We are using the same set of CRViewer properties in both cases:
    - DisplayGroupTree = False
    - DisplayToolbar = False
    - HasDrillUpButton = Flase
    - HasRefreshButton = False
    - HasToggleGroupTreeButton = Fasle
    - HasViewList = False
    - HasZoomFactorList = False
    - EnableViewState = True
    4) Here's a screenshot of of the .rpt file opened in the VS 2012:
    We only want to render the graph image on the UI and not the whole page. Is there a property setting that will help us achive this or should we define explicit CSS styles to hide those areas?
    Thank you for looking into this!
    Avrosh

  • Problems displaying in IE

    While I love iWeb's ease of use, it seems to have serious problems displaying on IE. There is really no point blaming IE, since it is the dominant browser and most people who will see our sites will use it. The point of iWeb should be to allow people to communicate broadly and effectively, not just to Mac & Safari users.
    Lists do not work well. The indents do not display properly. Text in boxes shift alignment and location. Bullets show up with different sizes. I have had to hand indent and line space all the lists in the sites I make, which is a mess and not scaleable.
    See fieldsforkidsmamk.org.
    Are there any workarounds or fixes?
    The other obvious issues with iWeb are worth noting:
    * inconsistent display in browsers -- pages look different in Safari and Firefox, even on the Mac (let alone IE)
    * difficulty adding html code
    * page names must be identical to nav names, so pages with multiple words (Get Involved) display urls as /Get%20Involved (can't be corrected unless you have Get_Involved as a header.)
    * need to publish whole site for any change
    * need to publish all sites for each change to any site
    * can't change color, display, location, function etc for Nav
    I assume everyone is aware of these problems. The question is, what to do? Grin and bear it? Any help, tips or ideas would be appreciated.
    Thanks!
    MacBook Mac OS X (10.4.8)
    MacBook Mac OS X (10.4.8)
    MacBook Mac OS X (10.4.8)
    MacBook   Mac OS X (10.4.8)  

    * page names must be identical to nav names, so pages
    with multiple words (Get Involved) display urls as
    /Get%20Involved (can't be corrected unless you have
    Get_Involved as a header.)
    You can fix this the same way you add html code, by post processing.
    * need to publish all sites for each change to any
    site
    You can fix this by separating your sites into different Domain files so you only publish one at a time.
    Contrary to the other response, "encoding" is not connected to the points you made. There is never any need to add a UTF-8 "tag" to an iWeb page. If you see question marks or Â's when your page is displayed on any browser, Mac or PC, then you may need to fix your ftp or server settings.

  • Problems displaying rtf memo fields

    Post Author: Davidm
    CA Forum: General
    We use Crystal Reports X to run reports on an Access database with a significant number of rtf memo fields. We use Total Access Memo to allow extended use of rtf within Access as our users require the additional formatting capabilities that this offers.
    However, there are considerable problems displaying items like bullet points, tables and hyperlinks in the Crystal Viewer with tables in particular coming out in a real mess with all entries in the table being displayed in a list with a small square marking each cell at the end of each line.
    Curiously, if you preview the report in the full version of Crystal X, it appears a bit better with the hyperlinks still underlined (bullet points still vanish) and rows in rtf tables are at least presented as a row even if the columns are not ordered and mixed (with no bounding cells visible).
    Firstly, is this disparity of end result between full Crystal X Print Preview and the Crystal X Viewer fixable?
    Secondly, is the limited handling of rtf tags likely to be solved in the next release of Crystal?

    Hi Mathias,
    If I caught you correctly, you want to display data in Adobe forms in form of tabel, right?
    So, follow the steps:
    1. Insert one sub form on your adobe form.
    2. Set its type as "flow content" in object->subform property.
    3. Set flow direction as "Table".
    4. Insert another subform inside this subform.
    5. set its type as "flow content" and flow direction as "Table row".
    6. Now, choose binding tab, and there check "repeat subform for each Data item check box" and specify min. count for your rows.
    7. Now, insert your column fields inside this sub form once.
    8. Format its look and feel as you want.
    When you run this application, it will show you multiple data as table on Adobe form.
    Regards,
    Bhavik

  • Problem displaying php page in dreamweaver

    I am having problems displaying php scripting on dreamweaver.
    Need your advice.
    Installed dreamweaver 8, Coldfusion 7, mysql, php5.2 (using
    windows installer).
    Created file test.php ror testing containing
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN" "
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="
    http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    <body>
    date is:<b><?php echo Hello ?></b>
    </body>
    </html>

    ulises_arsi wrote:
    > I am having problems displaying php scripting on
    dreamweaver.
    Tell us what the problems are.
    > Installed dreamweaver 8, Coldfusion 7, mysql, php5.2
    (using windows installer).
    PHP needs to be configured with a web server, such as Apache
    or IIS.
    ColdFusion is also a webserver, but as far as I know, it
    cannot be
    configured to serve PHP pages.
    > date is:
    <?php echo Hello ?>
    The only thing that would display is an error message. Hello
    needs to be
    enclosed in quotes:
    <?php echo 'Hello'; ?>
    David Powers
    Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    http://foundationphp.com/

Maybe you are looking for