I used the zoom and scroll chart codes based on the description of the following swtchart document, but it does not work. Is there a solution?
Description for zoom:
Zoom of axis is an operation to zoom in or out the range of axis.
The following example code zooms in and out the range of Y axis.
IAxis yAxis = axisSet.getYAxis(0);
yAxis.zoomIn();
yAxis.zoomOut();
Description for Scroll:
Scroll of axis is an operation to scroll up or down the range of axis.
The following example code scrolls up or down the range of Y axis.
IAxis yAxis = axisSet.getYAxis(0);
yAxis.scrollUp();
yAxis.scrollDown();
My code:
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swtchart.Chart;
import org.eclipse.swtchart.IAxis;
import org.eclipse.swtchart.IAxisSet;
import org.eclipse.swtchart.ILineSeries;
import org.eclipse.swtchart.ISeries.SeriesType;
public class LineChartExample {
private static final double[] ySeries = { 0.0, 0.38, 0.71, 0.92, 1.0, 0.92,
0.71, 0.38, 0.0, -0.38, -0.71, -0.92, -1.0, -0.92, -0.71, -0.38 };
/**
* The main method.
*
* @param args
* the arguments
*/
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Line Chart");
shell.setSize(500, 400);
shell.setLayout(new FillLayout());
createChart(shell);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
/**
* create the chart.
*
* @param parent
* The parent composite
* @return The created chart
*/
static public Chart createChart(Composite parent) {
// create a chart
Chart chart = new Chart(parent, SWT.NONE);
// set titles
chart.getTitle().setText("Line Chart");
chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points");
chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");
// create line series
ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet()
.createSeries(SeriesType.LINE, "line series");
lineSeries.setYSeries(ySeries);
IAxisSet axisSet = chart.getAxisSet();
IAxis yAxis = axisSet.getYAxis(0);
yAxis.zoomIn();
yAxis.zoomOut();
yAxis.scrollUp();
yAxis.scrollDown();
// adjust the axis range
chart.getAxisSet().adjustRange();
return chart;
}
}
The following are example from Github that could help you:
Handling
MouseWheelListener
MouseEvent
for ZoomIn/ZoomOut:Reference: https://github.com/harmanea/reSpefo/blob/master/reSpefo/src/cz/cuni/mff/respefo/listeners/MouseWheelZoomListener.java
https://javadoc.scijava.org/Eclipse/org/eclipse/swt/events/MouseWheelListener.html
KeyAdapter
Reference: https://github.com/harmanea/reSpefo/blob/master/reSpefo/src/cz/cuni/mff/respefo/listeners/DefaultKeyListener.java
https://download.eclipse.org/rt/rap/doc/3.13/guide/reference/api/org/eclipse/swt/events/KeyAdapter.html
As you can see in the examples above, it is not simply just calling zoomIn/zoomOut, and scrollUp/scrollDown, you need to make it aligned with Key Listeners, and/or MouseWheel events.
In your code, you zoomedIn/Zoomed out...so basically they cancelled each other.