programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Paul Clapham
• Bear Bibeault
• Junilu Lacar
Sheriffs:
• Jeanne Boyarsky
• Tim Cooke
• Henry Wong
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• salvin francis
• Frits Walraven
Bartenders:
• Scott Selikoff
• Piet Souris
• Carey Brown

# Getting the X, Y coordinate values in a JChart

Ranch Hand
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

Ranch Hand
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
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
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).]

Ranch Hand
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

Meghna ks
Ranch Hand
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);
JScrollPane1.getViewport().setBackground(new java.awt.Color(0,102,204));
JScrollPane1.setBounds(12,12,1000,350);
chart1.setToolTipText("x,y");
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);
JLabel1.setBackground(new java.awt.Color(0,102,204));
JLabel1.setBounds(12,372,1000,24);
//}}
//{{REGISTER_LISTENERS
SymMouseMotion aSymMouseMotion = new SymMouseMotion();
//}}
}
//{{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();
//}}
{
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