Hi Jonathan,
The previous code within mouseMove event doesn't do anything except having index and label values. I don't want to print the label, but want to DISPLAY the label on the scatter chart when mouse moves over the points. I am asking you how to do this.
MarksTip tool already does this for me only using this code you posted:
Code: Select all
Points p = new Points(tChart1.getChart());
p.add(3,6);
p.add(4,7);
p.add(5,10);
StringList sl = new StringList(3);
sl.setString(0, "one one");
sl.setString(1, "two two");
sl.setString(2, "three three");
p.setLabels(sl);
MarksTip mt = new MarksTip(tChart1.getChart());
mt.setStyle(MarksStyle.LABEL);
Anyway, you can also do this manually using annotation tools or custom drawing on charts canvas, for example:
Code: Select all
private void initChart() {
Points p = new Points(tChart1.getChart());
p.add(3,6);
p.add(4,7);
p.add(5,10);
StringList sl = new StringList(3);
sl.setString(0, "one one");
sl.setString(1, "two two");
sl.setString(2, "three three");
p.setLabels(sl);
tChart1.addMouseMotionListener(new MouseMotionListener() {
public void mouseDragged(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
tChartMouseListened(e);
}
});
}
private void tChartMouseListened(java.awt.event.MouseEvent e) {
Series s = tChart1.getSeries(0);
int index = s.clicked(e.getX(),e.getY());
if (index != -1) {
String yVal = String.valueOf(s.getYValues().getValue(index));
String label = s.getLabels().getString(index);
tChart1.getTools().clear();
Annotation annotation1 = new Annotation(tChart1.getChart());
annotation1.getShape().setCustomPosition(true);
annotation1.getShape().setLeft(e.getX());
annotation1.getShape().setTop(e.getY());
annotation1.setText(yVal + " - " + label);
}
}
If this doesn't help please attach a simple example project we can run "as-is" to reproduce your problem here.
Thanks in advance.