use of org.eclipse.swtchart.extensions.core.ICustomSelectionHandler in project swtchart by eclipse.
the class LineSeries_Selection_Part method initialize.
private void initialize() throws Exception {
this.setLayout(new GridLayout(1, true));
this.setBackground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
//
Composite compositeInfo = new Composite(this, SWT.NONE);
GridData gridDataComposite = new GridData(GridData.FILL_HORIZONTAL);
gridDataComposite.horizontalAlignment = SWT.BEGINNING;
compositeInfo.setLayoutData(gridDataComposite);
compositeInfo.setLayout(new GridLayout(13, false));
//
createLabel(compositeInfo, "X-Start:");
textRangeXStart = createText(compositeInfo);
createLabel(compositeInfo, "X-Stop:");
textRangeXStop = createText(compositeInfo);
createLabel(compositeInfo, "Y-Start:");
textRangeYStart = createText(compositeInfo);
createLabel(compositeInfo, "Y-Stop:");
textRangeYStop = createText(compositeInfo);
createLabel(compositeInfo, "X:");
textX = createText(compositeInfo);
createLabel(compositeInfo, "Y:");
textY = createText(compositeInfo);
createButtonReset(compositeInfo);
//
lineChart = new LineChart(this, SWT.NONE);
lineChart.setLayoutData(new GridData(GridData.FILL_BOTH));
lineChart.getBaseChart().addCustomRangeSelectionHandler(new ICustomSelectionHandler() {
@Override
public void handleUserSelection(Event event) {
BaseChart baseChart = lineChart.getBaseChart();
Range rangeX = baseChart.getAxisSet().getXAxis(BaseChart.ID_PRIMARY_X_AXIS).getRange();
Range rangeY = baseChart.getAxisSet().getYAxis(BaseChart.ID_PRIMARY_Y_AXIS).getRange();
DecimalFormat decimalFormatX = baseChart.getDecimalFormat(IExtendedChart.X_AXIS, BaseChart.ID_PRIMARY_X_AXIS);
DecimalFormat decimalFormatY = baseChart.getDecimalFormat(IExtendedChart.Y_AXIS, BaseChart.ID_PRIMARY_Y_AXIS);
textRangeXStart.setText(decimalFormatX.format(rangeX.lower));
textRangeXStop.setText(decimalFormatX.format(rangeX.upper));
textRangeYStart.setText(decimalFormatY.format(rangeY.lower));
textRangeYStop.setText(decimalFormatY.format(rangeY.upper));
}
});
lineChart.getBaseChart().addCustomPointSelectionHandler(new ICustomSelectionHandler() {
@Override
public void handleUserSelection(Event event) {
BaseChart baseChart = lineChart.getBaseChart();
double x = baseChart.getSelectedPrimaryAxisValue(event.x, IExtendedChart.X_AXIS);
double y = baseChart.getSelectedPrimaryAxisValue(event.y, IExtendedChart.Y_AXIS);
//
DecimalFormat decimalFormatX = baseChart.getDecimalFormat(IExtendedChart.X_AXIS, BaseChart.ID_PRIMARY_X_AXIS);
DecimalFormat decimalFormatY = baseChart.getDecimalFormat(IExtendedChart.Y_AXIS, BaseChart.ID_PRIMARY_Y_AXIS);
textX.setText(decimalFormatX.format(x));
textY.setText(decimalFormatY.format(y));
//
try {
ISeries series = baseChart.getSeriesSet().getSeries(DATA_POINT_SERIES);
double xSelected = xValues.floor(x);
double ySelected = yValues.get(xSelected);
double[] xSeries = new double[] { xSelected };
double[] ySeries = new double[] { ySelected };
series.setXSeries(xSeries);
series.setYSeries(ySeries);
baseChart.redraw();
} catch (Exception e) {
//
}
}
});
applyChartSettings();
}
Aggregations