Win a copy of Raising Young Coders: A Parent’s Guide to Teaching Programming at Home this week in the General Computing forum!
Forums Login/signup

Getting the X, Y coordinate values in a JChart

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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).]
+Pie Number of slices to send: Send

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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
err....maybe I wasn't too clear...
I was asking for the API link if there is any?
- satya

reply
reply
This thread has been viewed 1972 times.
Similar Threads
Trying to implement autoscrolling on a jpanel that has a jscrollpane.
EventHandling on pi-chart
Finding mouse X,Y without a MouseEvent object
Capturing the X & Y values in a mousemoved event
Chart problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Jun 27, 2025 09:08:56.