Results 1 to 11 of 11
  1. #1
    homi is offline Member
    Join Date
    Jul 2009
    Posts
    5
    Rep Power
    0

    Default interactive scattering xy plots using java

    Hi there ,

    How can I make a graph interactive using java ? When I move my mouse along x or y axis the values should be change in the text fields.
    Thanks in advance

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Figure out a way to translate between the component view and your data model.
    You can set up an AffineTransform (which uses matrix math) to do this for you. Here's an example of how you might approach this.
    Attached Files Attached Files

  3. #3
    homi is offline Member
    Join Date
    Jul 2009
    Posts
    5
    Rep Power
    0

    Default interactive plots

    Thank you so much Sir,
    I got the point, well, I just need to save the highlighted values ( i.e in red color) , and the user can drag and drop them at new place in the plot and the array will be updated.

  4. #4
    homi is offline Member
    Join Date
    Jul 2009
    Posts
    5
    Rep Power
    0

    Default Interactive Graph

    Hi there,

    Is there any method to take values of highlighted data model from graph into text fields without using affine transform? When user drag the pixel values and drop them at somewhere else the text field value changed with the new values
    Thanks in advance

  5. #5
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    You can translate the values without using AffineTransform. Look at the xScale and yScale statements in the setTransform method. You do something similar to translate from view to model for your textField values.

  6. #6
    homi is offline Member
    Join Date
    Jul 2009
    Posts
    5
    Rep Power
    0

    Default Interactive Graph

    Thank you so much for taking interest in my problem and helping me
    Do you have any idea to drag and drop data model within graph using scattering graphs ? Any example code ??

  7. #7
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Java Code:
    class GraphicComponent extends JPanel {
        // make points of view data
        Point[] points;
    
        public void setPoint(Point p, int x, int y) {
            p.setLocation(x,y);
            repaint();
        }
    
        protected void paintComponent(Graphics g) {
            draw points
        }
    
        public static void main(...
            GraphicComponent gc = new GraphicComponent
            make and show gui
            DragClass dc = new DragClass(gc);
            gc.addMouseListener(dc)
            gc.addMouseMotionListener(dc)
    }
    
    class DragClass extends MouseAdapter {
        GraphicComponent component;
        Point selPoint;
        boolean okayToDrag = false;
        Point offset = new Point();
        int closeEnough = min dist for selection
    
        public DragClass(GraphicComponent gc) {
            component = gc;
        }
    
        public void mousePressed(MouseEvent e) {
            Point p = e.getPoint()
            run through all the points in component array to
            see if the mouse is close enough for a selection
            if so, select the point: selPoint = point in array
                   okayToDrag = true
                   offset.x = p.x - selPoint.x
                   offset.y = p.y - selPoint.y
                   break
        }
    
        public void mouseReleased(MouseEvent e) {
            okayToDrag = false;
        }
    
        public void mouseDragged(MouseEvent e) {
            if okayToDrag
                x = e.getX - offset.x
                y = e.getY - offset.y
                component.setPoint(selPoint, x, y)
        }
    }

  8. #8
    homi is offline Member
    Join Date
    Jul 2009
    Posts
    5
    Rep Power
    0

    Default

    Hi Sir,

    In your code the Point class is a new thing for me , how can i make an array of data type double using Point? In the given code code i understand the mouse events but i am still unable to make a complete application. please help me..

    // make points of view data
    Point[] points;

  9. #9
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Here’s an example.
    Attached Files Attached Files

  10. #10
    homistar is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default interactive graphpanel

    Respected Members,
    Hi,


    Can anybody help me to complete these mouse events in the given code (DragClass.java) ??
    I will be really really grateful.
    Although the above given examples are excellent but I am still facing to drag and released values of array on to the plot and then save them into array again ( new values)
    so that if I refresh or update my graph the new values should appeared.

    Thanks in advance

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Dear new poster, first welcome to the forum.

    I have to admit to being somewhat on the cynical side, and my first interpretation of your post is that you desire someone to do this code for you. I'm sure that this isn't true, and I recommend that you do this: make a first best effort at solving your problem, and then show us your code, errors and all, and I'm sure that many will be very glad to help you. Oh and please start a new thread since this is a new person's (your) problem we're dealing with.

    Best of luck.

Similar Threads

  1. Interactive TouchScreen - Java Programmers wanted
    By indigovision in forum Jobs Offered
    Replies: 0
    Last Post: 02-26-2009, 04:23 PM
  2. Interactive vector map in Java
    By nenadm in forum AWT / Swing
    Replies: 1
    Last Post: 02-17-2009, 08:52 PM
  3. Replies: 0
    Last Post: 01-14-2009, 01:26 PM
  4. Java Interactive Profiler 1.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 06-24-2007, 08:47 AM
  5. Java Interactive Profiler 1.1 rc 1
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-04-2007, 08:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •