Displaying float numbers in a graph

Good afternoon!
I need to dislay my output results from the loop into graph. My results are all float numbers, so I cannot use drawLine. Please help if you can. I would really appreciate it.
Sincerely,
Byryndyk

Correction: yOrigin in post 6 is accurate for min < 0.
This works better . . .
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
public class PlottingFloats {
  static class Plotter extends JPanel {
    float PAD = 25;
    java.util.List dataList = new ArrayList();
    public Plotter() {
      setBackground(Color.white);
      setPreferredSize(new Dimension(400,300));
    public void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D)g;
      float width = getWidth();
      float height = getHeight();
      float xStep = (width - 2*PAD)/(dataList.size() - 1);
      float x = PAD;
      float y;
      // scale data
      float max = ((Float)Collections.max(dataList)).floatValue();
      float min = ((Float)Collections.min(dataList)).floatValue();
      float vertSpace = height - 2*PAD;
      float yOffset = height - PAD;
      float scale = vertSpace/(max - min);
      float yOrigin = vertSpace * max/(max - (min > 0 ? 0 : min)) + PAD;
      // draw ordinate
      g2.draw(new Line2D.Float(PAD, PAD, PAD, yOffset));
      // draw abcissa
      g2.draw(new Line2D.Float(PAD, yOrigin, width - PAD, yOrigin));
      // label ordinate limits
      g2.drawString(String.valueOf(max), 10, PAD - 10);
      g2.drawString(String.valueOf(min), 10, yOffset + PAD/2);
      g2.setStroke(new BasicStroke(4f));
      g2.setPaint(Color.red);
      for(int j = 0; j < dataList.size(); j++) {
        y = yOrigin - scale * ((Float)dataList.get(j)).floatValue();
        g2.draw(new Line2D.Float(x, y, x, y));
        x += xStep;
    protected void plot(float input) {
      dataList.add(new Float(input));
      repaint();
  public static void main(String[] args) {
    float[] data = {
      100f, 220f, 12.9f, 65f, 47.3f, 15f, 190f, -18f
    Plotter plotter = new Plotter();
    for(int j = 0; j < 8; j++)
      plotter.plot(data[j]);
    JFrame f = new JFrame("Plotting Floats");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(plotter);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

Similar Messages

  • How to display Values(Numbers) in 3D Graph?

    Hi!
    PFA below. Its regarding the screen shot of 3D Graph.
    As we can see in the picture that the values are not accurate to view. So its better to display values(numbers) on top of each tower in 3D Graph.
    How to display that? Kindly suggest me any solution.
    With Regards,
    Yarnagula Sudhir.

    Hi!
    PFA below. Its regarding the screen shot of 3D Graph.
    As we can see in the picture that the values are not accurate to view. So its better to display values(numbers) on top of each tower in 3D Graph.
    How to display that? Kindly suggest me any solution.
    With Regards,
    Yarnagula Sudhir.

  • Display float numbers in APEX report

    Hello,
      I have an  interactive report and simple report based on a table with float numbers. Problem is, float numbers with value between 0 and 1 are shown ".1" not "0.1"
    For example, for values 0.1, 1 and 12.1 I get:
    .1
    1
    12.1
      If I add format mask FM999999999999990D99999 to this field, I fix ".1" value, but value "1" becomes "1." which is bad:
    1
    0.1
    1.
    12.1
    What I would like to see in a report is:
    0.1
    1
    12.1
    How could I do it?
    I wrote function which makes needed result as a varchar2 value. Data in reports shows fine, but then problem with sorting arised - data is being sorted as text, not as number, for example:
    1.1
    11.2
    7
    Any ideas?
    Thank you

    So finally seems everything is working now. I even do not need additional column with required format.  And i guess it will work on all apex 4 versions
    Have float column (named lets say ir_float ) and do not use any format on it, leave it as it is. Then the only bad case is ".1" instead of "0.1"
    Add dynamic action after refresh, specify region (which must have template, even for IR) and add java script action:
    For interactive reports:
    $('.apexir_WORKSHEET_DATA td[headers="ir_float"]').each(function(){   
        if(jQuery(this).text().substr(0,1) == '.'){
             jQuery(this).prepend('0')
    For classic reports:
    $('#R930945330216409887 td[headers="ir_float"]').each(function(){   
        if(jQuery(this).text().substr(0,1) == '.'){
             jQuery(this).prepend('0')
    BIG thanks for your ideas fac586
    Giedrius

  • "0" doesn't display before comma in float numbers...

    Hi fellow APEX users,
    Have you ever experienced this issue with float numbers in your APEX forms?
    When I type float numbers between -1 and 1 in forms (e.g. 0,7 or -0,2), and after having submitted the form then reloaded it for editing, "0" doesn't display before the comma.
    For example I got:
    *,7* instead of *0,7*
    -,2 instead of -0,2
    etc.
    If I look in SQL Workshop, I see the same (no "0") but I'm pretty sure that the value is properly recorded in the database.
    The thing is that it's not very nice for the end users, as they can think the value is wrong.
    Does anybody have a solution to display proper float numbers with "0" in the forms?
    For info I use the NUMBER type.
    Any help much appreciated!
    Thanks,
    Romain.
    Edited by: romain.apex on Feb 5, 2012 8:30 PM

    Hi Peter!
    Of what type is your item? Display as text or do you use the item value for further computations.
    If it is only for means of displaying the correctly formatted number, I'd change the item source to a query and would equip the desired column with a to_char function like:
    select to_char(str_be_main, 'fm999G999G990D00') from yourtable where ...You could also use a post calculation computation and enforce the format there:
    to_char(:P2027_YOUR_ITEM,'fm999G999G990D00')Maybe this helps!
    Brgds,
    Seb
    Edited by: skahlert on 11.02.2011 07:53

  • How to display Values(Numbers) over every individual Towers in 3D Graph?

    Hi!
    PFA below. Its regarding the screen shot of 3D Graph.
    As we can see in the picture that the values are not accurate to view. So its better to display values(numbers) on top of each tower in 3D Graph.
    How to display that? Kindly suggest me any solution.
    With Regards,
    Yarnagula Sudhir.
    Message was edited by: Yarnagula Sudhir
    Message was edited by: Yarnagula Sudhir

    You do realize that this forum is for Adobe InDesign?

  • Problem to display big numbers in javascript

    I try to display a big number but the result is not correct.
    My code:
    var n = 1771653332244424314244444;
    console.println(util.printf("Float format: %f", n));
    Result:
    Float format: 1771653332244424300000000.
    The result is round. Why ?
    How to do to display the good number ?
    David

    > The result is round. Why ?
    This is the normal limitation of the representation of floating numbers.
    > How to do to display the good number ?
    You can use a JavaScript library like BigInt.js:
    http://www.leemon.com/crypto/BigInt.html

  • How to display page numbers in report

    hi all,
    i would like to know how to display page numbers in this format " 1 of 5" in the report.
    Any help would be much appreciated.
    thanks
    seema

    Hi,
    Check this too...
    Page No. in ALV output
    If you query is solved, kindly close the thread.
    Regards,
    Anjali
    Message was edited by: Anjali Devi Vishwanathan

  • How to display Page numbers in XMLreport(on PDF)

    hi all,
    we have a requirement where we need to display page numbers(e.g.page 1 of 10),on an XML report.
    can anybody suggest me the solution.

    Hi,
    Check this too...
    Page No. in ALV output
    If you query is solved, kindly close the thread.
    Regards,
    Anjali
    Message was edited by: Anjali Devi Vishwanathan

  • Help with display of numbers

    First of all I have to say the tutorials on this site are extremely helpful. My instructor wants all our java code written as Object Oriented and when I did a search on here for Object Oriented it totally helped out. Now I just need help with the display of numbers, my code works perfectly fine except that the number has wayyyyyyyyyyy to many decimal points after it. I only wanted two.
    public class Mortgage
         double mtgAmount;
         double mtgTerm;
         double mtgRate;
         double monthPymt;
              public void Amount(double newValue)
                     mtgAmount = newValue;
              public double Amount()
                   return mtgAmount;
              public void Term(double newValue)
                     mtgTerm = newValue;
              public double Term()
                   return mtgTerm;
              public void Rate(double newValue)
                     mtgRate = newValue;
              public double Rate()
                   return mtgRate;
              public void calcmonthPymt(double newValue)                            //(LoanAmt * Rate) / (1- Math.pow(1+Rate,-Term));
                     monthPymt = (newValue);
              public void display()
              System.out.println ("The Mortgage Amount is:" +(Amount( ) * Rate( )) / (1- Math.pow(1+Rate( ),-Term( ))));
         public static void main (String[] args)
                     Mortgage Mortgage1=new Mortgage();
                     Mortgage1.Amount(200000);
                     Mortgage1.Term(360);
                     Mortgage1.Rate(.0575);
                     Mortgage1.display();
    }

    I figured it out, the math is wrong I think but I got everything to display correctly
    import java.io.*;
    import java.text.*;
    import java.text.DecimalFormat;
    public class Mortgage
         double mtgAmount;
         double mtgTerm;
         double mtgRate;
         double monthPymt;
         DecimalFormat money = new DecimalFormat("$0.00");
              public void Amount(double newValue)
                     mtgAmount = newValue;
              public double Amount()
                   return mtgAmount;
              public void Term(double newValue)
                     mtgTerm = newValue;
              public double Term()
                   return mtgTerm;
              public void Rate(double newValue)
                     mtgRate = newValue;
              public double Rate()
                   return mtgRate;
              public void calcmonthPymt(double newValue)                            //(LoanAmt * Rate) / (1- Math.pow(1+Rate,-Term));
                     monthPymt = (newValue);
              public void display()
              monthPymt = (Amount( ) * Rate( )) / (1- Math.pow(1+Rate( ),-Term( )));
              System.out.printf("The payment amount is:$%.2f", monthPymt);
              System.out.println();
         public static void main (String[] args)
                     Mortgage Mortgage1=new Mortgage();
                     Mortgage1.Amount(200000);
                     Mortgage1.Term(360);
                     Mortgage1.Rate(.0575);
                     Mortgage1.display();
    }

  • Why the timetable cannot be displayed correctly  in the Gantt graph?

    Hi, jdev 11.1.2.3
    Have a table(task_list) with fields as: id,type, title, content,begin_date,end_date,status...
    and set EO/VO for the table, and drag data control of TaskListView1 Into a jspx page to create Project Gantt as:
    Task id*:id,
    Task type :type,
    Start Time*: BeginDate,
    End time*: EndDate,
    And select all table columns.
    After running, the page showed a Gannt graph with all fields displayed on the left panel (the begin_date,end_date have values of different dates),but blank on the right timetable panel, what ever the timetable's view (week,month,year,project) will be chosen.
    Why the timetable cannot be displayed correctly in the Gantt graph?
    Thanks.

    That is the default text that Firefox displays on a tab.<br />
    As soon as the image has loaded then that text is replaced by the image.
    If you keep seeing that text then something is blocking images.
    See:
    * http://kb.mozillazine.org/Images_or_animations_do_not_load

  • Displaying negative numbers under certain conditions

    I have a Crystal Report which I am developing and need to display positive numbers as negative, but only under certain conditions.  I did not see anything on this type of questions so I decided to join and post it up myself.  This is a transfer report so if the location number entered in the parameter list is the SHIPPING location, I need to display retail, cost, and totals as negative.  Here is the formula which I came up with for ext cost, but it is returning all zeros.  I cannot seperate the to and from locations in the parameters because this report needs to display both in and out of that location.
    if totext({?loc}) = totext({Command.SHIP_FROM}) then ({Command.EXT_COST}*-1)
    Any suggestions?  Appreciate the help!

    Hi Jon,
    If it returns zeroes, then it means that this part of the code fails:
    totext({?loc}) = totext({Command.SHIP_FROM})
    Do you have records where the value entered in the 'loc' prompt matches with records in the SHIP_FROM column on the report?
    See if this helps:
    if totext({?loc},0,"") = totext({Command.SHIP_FROM},0,"") then ({Command.EXT_COST}*-1)
    -Abhilash

  • Displaying line numbers in oracle Sql developer

    hi guys, can someone tell me how to display line numbers in oracle sql developer Version 2.1.1.64?.

    I absolutely didn't know where it was, so I had to look for it, and it appears easy to find.
    Hit Tools
    Hit Preferences
    Expand Code Editor
    Navigate to line gutter
    Now click 'Show line numbers'
    And, oh yes, there is a separate sql developer forum. Please keep sql developer issues in that forum.
    Sybrand Bakker
    Senior Oracle DBA

  • Help regarding program to display even numbers

    plz send me a program to display even numbers from 1 to 100.

    DATA : VAL TYPE I.
    DO 100 TIMES.
    COMPUTE VAL = SY-INDEX MOD 2.
    IF VAL EQ 0.
    WRITE : / 'Even NOs are' , SY-INDEX.
    *ELSE.
    *WRITE
    ENDIF.
    ENDDO.
    REGARDS
    SHIBA DUTTA

  • Displaying row numbers in tables

    Is there a way to get JTable to display row numbers on the left-most side of the table? Are there any functions in JTable that will allow you to do this?
    I am thinking that to do this, I will probably need to add a column to my table model and make the first column and uneditable JLabel that shows the row number.
    Thanks for any help.
    Mike Ryan

    Ok , the class i am pulling this code from is 500+ lines of code, so I will try to pull out only the important pieces.
    private DefaultTableModel theNorthernModel;
    private JTable theNorthernTable;
    private DefaultTableCellRenderer[] theRenderer;
    private JScrollPane theNorthernPane;
    private Object[] rowTitles = {"1", "2", "3",  "4", "5",  "6", "7"};//
    private Object[] colTitles  = {"one","two","three","four","five","six"};
         theNorthernModel = new DefaultTableModel(rowTitles.length,colTitles.length);
              theNorthernTable = new JTable(theNorthernModel);
              theNorthernTable.setCellSelectionEnabled(false);
              theNorthernTable.setEnabled(false);
              theNorthernTable.getTableHeader().setReorderingAllowed(false);
              theNorthernPane  = new JScrollPane(theNorthernTable);
              theNorthernPane.setPreferredSize(new Dimension(600, 150));
    //this is the stuff you want          
    ListModel listModel = new AbstractListModel() {
                 public int getSize() {
                         return rowTitles.length;
                public Object getElementAt(int index) {
                     return rowTitles[index];
            JList rowHeader1 = new JList(listModel);
            rowHeader1.setBackground(theNorthernPane.getBackground());
            rowHeader1.setFixedCellWidth(140);
            theNorthernPane.setViewportView(theNorthernTable);
            theNorthernPane.setRowHeaderView(rowHeader1);
            rowHeader1.setCellRenderer(new RowHeaderRenderer(theNorthernTable));
    theRenderer = new DefaultTableCellRenderer[6];
              for(int i = 0; i< 6; i++) {
                   theRenderer[i] = new DefaultTableCellRenderer();     
    theColumnModel = (DefaultTableColumnModel)theNorthernTable.getColumnModel();
    * RowHeaderRenderer renders the panel's rows
    class RowHeaderRenderer extends JLabel implements ListCellRenderer {
         * Constructor creates all cells the same
         * To change look for individual cells put code in
         * getListCellRendererComponent method
        RowHeaderRenderer(JTable table) {
            JTableHeader header = table.getTableHeader();
            setOpaque(true);
            setBorder(UIManager.getBorder("TableHeader.cellBorder"));
            setHorizontalAlignment(CENTER);
            setForeground(header.getForeground());
            setBackground(header.getBackground());
            setFont(header.getFont());
         * Returns the JLabel after setting the text of the cell
        public Component getListCellRendererComponent( JList list,
        Object value, int index, boolean isSelected, boolean cellHasFocus) {
            setText((value == null) ? "" : value.toString());
            return this;
    }

  • My messages displays mostly numbers of contacts, not contacts, why?

    I turned my iPhone 4s on today and suddenly half of my messages are displayed as numbers, not contacts. I don't understand why, I couldn't find any info in the settings section.

    contact are not an issue http://thunderbirdtweaks.blogspot.com.au/2014/10/sync-hotmailoutlookcom-contacts-with.html
    Calendar will continue to be a problem until Microsoft makes them available in a format that is standards based.
    Google, much a I question their integrity make use of Open standards. Yahoo, even as they stumble from disaster to snafu also use standards. GMX the largest provider in Europe I am told, also uses standards. Even Apple manage to use standards. Only Microsoft stands out there using proprietary protocols that must be licensed from them. It is however a good way to ensure vendor lock in. They have no iTunes to keep the customers loyal and spending money

Maybe you are looking for