Page 1 of 1
Drag Functionality
Posted: Mon Oct 03, 2016 5:54 pm
by 17478810
Hi,
I know TeeChart allows DragPoint functionality where we can move points, was wondering if we have functionality to move the entire series if a point is dragged, adjust the other data points once a data point is moved.
Re: Drag Functionality
Posted: Tue Oct 04, 2016 8:25 am
by yeray
Hello,
You could do this manually using events instead of using the DragPoint tool. Ie:
Code: Select all
private static void dragTest() {
tChart1.getHeader().setVisible(false);
tChart1.getAspect().setView3D(false);
tChart1.getZoom().setAllow(false);
Points points1 = new Points(tChart1.getChart());
points1.fillSampleValues(10);
tChart1.getAxes().getBottom().setMinMax(points1.getMinXValue(), points1.getMaxXValue());
tChart1.getAxes().getLeft().setMinMax(points1.getMinYValue(), points1.getMaxYValue());
tChart1.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
if (draggingSeries != null)
tChart1.setCursor(Cursor.HAND);
else {
int tmpIndex = -1;
for (int t = 0; t < tChart1.getSeriesCount(); t++) {
Series s = tChart1.getSeries(t);
if (s.getActive()) {
tmpIndex = s.clicked(e.getX(), e.getY());
}
}
if (tmpIndex > -1)
tChart1.setCursor(Cursor.HAND);
else
tChart1.setCursor(Cursor.DEFAULT);
}
}
@Override
public void mouseDragged(MouseEvent e) {
if ((draggingSeries != null) && (draggingIndex != -1)) {
double diffX = draggingSeries.getHorizAxis().calcPosPoint(e.getX())
- draggingSeries.getHorizAxis().calcPosPoint(OldXPos);
double diffY = draggingSeries.getVertAxis().calcPosPoint(e.getY())
- draggingSeries.getVertAxis().calcPosPoint(OldYPos);
for (int i = 0; i < draggingSeries.getCount(); i++) {
draggingSeries.getXValues().setValue(i, draggingSeries.getXValues().getValue(i) + diffX);
draggingSeries.getYValues().setValue(i, draggingSeries.getYValues().getValue(i) + diffY);
}
OldXPos = e.getX();
OldYPos = e.getY();
}
tChart1.refreshControl();
}
});
tChart1.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
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;
OldXPos = e.getX();
OldYPos = e.getY();
break;
}
}
}
}
@Override
public void mouseReleased(MouseEvent e) {
draggingSeries = null;
draggingIndex = -1;
}
});
}