This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Getting the X, Y coordinate values in a JChart Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Getting the X, Y coordinate values in a JChart" Watch "Getting the X, Y coordinate values in a JChart" New topic
Author

Getting the X, Y coordinate values in a JChart

Meghna ks
Ranch Hand

Joined: Mar 15, 2001
Posts: 122
Hi
I have a Line chart within a scrollpane. I've written a mousemoved event for the chart so that when I move the mouse over the chart, I should be able to get the X & Y values of the chart, not the position of the of the mouse when it is moved over the chart. Right now, the values that are shown when I move the mouse over the chart are the values of the X, Y coords of the mousemoved event wrt the scrollpane. Can someone throw some light on this ?!!
Thanks
Meghna
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Meghna,
I am a little confused with your question. If you have a canvas inside of a scrollpane and you have added a mouse listener to the canvas you get the X and Y related to the canvas. If we should happen to move the scrollpane we still get the x,y of the canvas. If you have a smaller area on the canvas that you are calling a chart then you have to make the math adjustment to figure out the chart x,y ...
Manfred.
Meghna ks
Ranch Hand

Joined: Mar 15, 2001
Posts: 122
Hi Manfred
The basic container here is the Applet. And then, there's the scrollpane in which the chart is contained. Now, suppose, the chart looks like this :

5
4
3 .(3,4.1)
2
1 .(1,1)
0 1 2 3 4 5
How do I retrieve the math for this particular problem ?!! I don't seem to come up with any logic. Please let me know if you've come across any solution for a similar situation. I'd greatly appreciate that.

Thanks
Meghna
Meghna ks
Ranch Hand

Joined: Mar 15, 2001
Posts: 122
Let me put the graph properly.
I hope this looks understandable, I'm sorry if it looks messy.

ps: added the [ code ] tags...incase it helps...
- satya

[This message has been edited by Madhav Lakkapragada (edited July 30, 2001).]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

Meghna:
much better I guess...
Also can I ask you to post the link for the JChart you have been talking about. Sorry, I couldn't find time to search.
Just curious to know,
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Meghna ks
Ranch Hand

Joined: Mar 15, 2001
Posts: 122
Here's the code snippet :
public chart()
{
//{{INIT_CONTROLS
setLayout(null);
setBackground(new java.awt.Color(0,102,204));
setForeground(java.awt.Color.white);
setSize(1015,400);
JScrollPane1.setOpaque(true);
JScrollPane1.setBorder(lineBorder1);
add(JScrollPane1);
JScrollPane1.getViewport().setBackground(new java.awt.Color(0,102,204));
JScrollPane1.setBounds(12,12,1000,350);
chart1.setToolTipText("x,y");
JScrollPane1.getViewport().add(chart1);
chart1.setBackground(new java.awt.Color(0,102,204));
chart1.setFont(new Font("Dialog", Font.BOLD, 14));
chart1.setBounds(0,0,996,346);
bevelBorder1.setHighlightOuterColor(java.awt.Color.darkGray);
bevelBorder1.setHighlightInnerColor(java.awt.Color.darkGray);
//$$ bevelBorder1.move(0,432);
lineBorder1.setThickness(2);
//$$ lineBorder1.move(24,432);
JLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
JLabel1.setOpaque(true);
JLabel1.setBorder(lineBorder1);
add(JLabel1);
JLabel1.setBackground(new java.awt.Color(0,102,204));
JLabel1.setBounds(12,372,1000,24);
//}}
//{{REGISTER_LISTENERS
SymMouseMotion aSymMouseMotion = new SymMouseMotion();
chart1.addMouseMotionListener(aSymMouseMotion);
//}}
}
//{{DECLARE_CONTROLS
javax.swing.JScrollPane JScrollPane1 = new javax.swing.JScrollPane();
com.symantec.itools.javax.swing.JChart chart1 = new com.symantec.itools.javax.swing.JChart();
com.symantec.itools.javax.swing.borders.BevelBorder bevelBorder1 = new com.symantec.itools.javax.swing.borders.BevelBorder();
com.symantec.itools.javax.swing.borders.LineBorder lineBorder1 = new com.symantec.itools.javax.swing.borders.LineBorder();
javax.swing.JLabel JLabel1 = new javax.swing.JLabel();
//}}
class SymMouseMotion extends java.awt.event.MouseMotionAdapter
{
public void mouseMoved(java.awt.event.MouseEvent event)
{
Object object = event.getSource();
if (object == chart1)
chart1_mouseMoved(event);
}
}
void chart1_mouseMoved(java.awt.event.MouseEvent event)
{
Integer x = new Integer(event.getX());
Integer y = new Integer(event.getY());
String str = "x = " + x.toString() + ", "+ "y = " + y.toString();
String chr = x.toString() + ", " + y.toString();
JLabel1.setText(str);
chart1.setToolTipText(chr);
if (point == null)
{
point = new Point(x.intValue(), y.intValue());
}
else
{
point.x = x.intValue();
point.y = y.intValue();
}
repaint();
}
Thanks
Meghna
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
err....maybe I wasn't too clear...
I was asking for the API link if there is any?
- satya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting the X, Y coordinate values in a JChart