Hi,
I am implementing a Dragpoint event for my chart in Java, and now I want to capture the values after the drag point event is done and save them to DB. I see the legend is being updated with the values but I am not able to capture the values. Can you suggest a way to capture the data after the Drag is complete
DragPoint Events in Java
Re: DragPoint Events in Java
Hello,
You can use events as in the following SWT example:
You can use events as in the following SWT example:
Code: Select all
static int draggingIndex = -1;
static Series draggingSeries = null;
static Point mousePos = null;
private static void dragTest() {
tChart1.getHeader().setVisible(false);
tChart1.getAspect().setView3D(false);
//tChart1.getLegend().setVisible(false);
tChart1.getZoom().setActive(false);
Points points1 = new Points(tChart1.getChart());
points1.fillSampleValues(10);
DragPoint dragPoints1 = new DragPoint(tChart1.getChart());
tChart1.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent arg0) {
mousePos = new Point(arg0.x, arg0.y);
}
});
dragPoints1.addDragListener(new DragListener() {
@Override
public void dragMoving(ChangeEvent e) {
if (draggingSeries == null) {
draggingIndex = ((DragPoint)e.getSource()).getDragPoint();
for (int t = 0; t < tChart1.getSeriesCount(); t++) {
Series s = tChart1.getSeries(t);
if (s.getActive()) {
int clickedIndex = s.clicked(mousePos);
if ((draggingIndex != -1) && (clickedIndex != -1) && (clickedIndex == draggingIndex)) {
draggingSeries = s;
break;
}
}
}
}
}
@Override
public void dragFinished(ChangeEvent e) {
if ((draggingSeries != null) && (draggingIndex != -1)) {
System.out.println(draggingSeries.getYValues().getValue(draggingIndex));
}
draggingSeries = null;
draggingIndex = -1;
}
});
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: DragPoint Events in Java
Can we do the same using Swing components. My project is a swing project?
Re: DragPoint Events in Java
Hello,
It's quite similar in Swing. I've improved the code a bit:
It's quite similar in Swing. I've improved the code a bit:
Code: Select all
static int draggingIndex = -1;
static Series draggingSeries = null;
private static void dragTest() {
tChart1.getHeader().setVisible(false);
tChart1.getAspect().setView3D(false);
//tChart1.getLegend().setVisible(false);
tChart1.getZoom().setActive(false);
Points points1 = new Points(tChart1.getChart());
points1.fillSampleValues(10);
DragPoint dragPoints1 = new DragPoint(tChart1.getChart());
tChart1.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (dragPoints1.getSeries() == null) {
for (int t = 0; t < tChart1.getSeriesCount(); t++) {
Series s = tChart1.getSeries(t);
if (s.getActive()) {
draggingIndex = s.clicked(e.getX(), e.getY());
if (draggingIndex != -1) {
draggingSeries = s;
break;
}
}
}
} else {
draggingIndex = dragPoints1.getSeries().clicked(e.getX(), e.getY());
if (draggingIndex != -1) {
draggingSeries = dragPoints1.getSeries();
}
}
}
});
dragPoints1.addDragListener(new DragAdapter() {
@Override
public void dragFinished(ChangeEvent e) {
if ((draggingSeries != null) && (draggingIndex != -1)) {
System.out.println(draggingSeries.getYValues().getValue(draggingIndex));
}
draggingSeries = null;
draggingIndex = -1;
}
});
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: DragPoint Events in Java
I have a chart with multiple Lines, Yet I want to enable just one of the lines as draggable. The other lines have to remain static.
Re: DragPoint Events in Java
Hello,
Have you tried to do it with the code I posted here?
http://www.teechart.net/support/viewtop ... 396#p72396
Have you tried to do it with the code I posted here?
http://www.teechart.net/support/viewtop ... 396#p72396
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: DragPoint Events in Java
Yes,
In that code I am able to move all the lines, here is what i am talking about.
I have a TChart with 4 lines, however I want to able to move only one of the lines using DragPoint Tool. The other 3 lines should not be moved. I tried to add series to DragPoint class constructor, but I am not able to get the chart to work how i want it to work.
In that code I am able to move all the lines, here is what i am talking about.
I have a TChart with 4 lines, however I want to able to move only one of the lines using DragPoint Tool. The other 3 lines should not be moved. I tried to add series to DragPoint class constructor, but I am not able to get the chart to work how i want it to work.
Re: DragPoint Events in Java
Hello,
Knowing the index of the series you want the dragging to be allowed (ie draggableSeriesIndex), you can change the mousePressed event to fit your needs. Ie:
Knowing the index of the series you want the dragging to be allowed (ie draggableSeriesIndex), you can change the mousePressed event to fit your needs. Ie:
Code: Select all
@Override
public void mousePressed(MouseEvent e) {
Series s = tChart1.getSeries(draggableSeriesIndex);
if (s.getActive()) {
draggingIndex = s.clicked(e.getX(), e.getY());
if (draggingIndex != -1) {
draggingSeries = s;
OldXPos = e.getX();
OldYPos = e.getY();
break;
}
}
}
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |