apologies if this is too obvious but i searched around the forum for a solution and couldnt find one.
Turns out it is super easy to drag a point - just implement a ChartMouseListener :
Code: Select all
@Override
public void chartMouseClicked(ChartMouseEvent event) {
if (ts!=null) {
ts = null;
chart.chartpanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
if (event.getEntity() instanceof XYItemEntity) {
selected(event);
}
}
protected void selected(ChartMouseEvent event) {
selected = (XYItemEntity) event.getEntity();
ts = ((TimeSeriesCollection) selected.getDataset()).getSeries(selected.getSeriesIndex());
xy = ts.getDataItem(selected.getItem());
chart.chartpanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
}
@Override
public void chartMouseMoved(ChartMouseEvent event) {
if (ts!=null){
moveTo(chart.plot.getRangeAxis().java2DToValue(event.getTrigger().getY(), chart.chartpanel.getChartRenderingInfo().getPlotInfo().getDataArea(), chart.plot.getRangeAxisEdge()));
}
}
protected void moveTo(double yNew) {
ts.delete(xy.getPeriod());
xy.setValue(yNew);
ts.add(xy);
}
HTH