SeriesSelectionModifier
SciChart features the SeriesSelectionModifier, which allows selection of the upmost RenderableSeries at a touch position:
Note
Examples of the SeriesSelectionModifier usage can be found in the SciChart Android Examples Suite as well as on GitHub:
SeriesSelectionModifier Usage
The SeriesSelectionModifier allows setting of SelectedSeriesStyle of IStyle type, which is applied to a RenderableSeries after it has been selected by the modifier. Internally, the modifier modifies the setIsSelected(boolean isSelected) property on the topmost RenderableSeries to make it selected and tries to apply the IStyle onto setSelectedSeriesStyle(renderableSeries.IStyle selectedSeriesStyle) property.
The SelectedSeriesStyle has to conform to the IStyle protocol, which requires implementation of the following:
Method | Description |
---|---|
tryApplyStyle(Object styleableObject) | In this method you have to make the desired changes to a RenderableSeries. It is called when a series gets selected. |
tryDiscardStyle(Object styleableObject) | In this method you have to discard all the changes made in the tryApplyStyle(Object styleableObject) call. |
getStyleableObjectType() | Provides the type of an object (RenderableSeries) that this Style is to be applied to. |
For convenience purposes, there is a base implementation provided in StyleBase<T> class. You can derive from it then you will only need to implement the applyStyleInternal(T styleableObject) and discardStyleInternal(T objectToStyle) methods instead. Please find a code sample below.
Note
If you need to be able to select multiple RenderableSeries of different types, you can return the IRenderableSeries as the RenderableSeries type, as it is shown in the code sample below.
Alternatively, it is possible to have several SeriesSelectionModifiers instances with IStyles for different RenderableSeries types by calling setReceiveHandledEvents(boolean receiveHandledEvents) with true
.
Adding a SeriesSelectionModifier to a Chart
Any Chart Modifier can be added to a SciChartSurface via the chartModifiers property and SeriesSelectionModifier is no difference.
In the example below, we will create SelectedSeriesStyle and use it with SeriesSelectionModifier:
class SelectedSeriesStyle extends StyleBase<IRenderableSeries> {
private final PenStyle selectedStrokeStyle = new SolidPenStyle(ColorUtil.White, true, 4.0f, null);
private final EllipsePointMarker selectedPointMarker = new EllipsePointMarker();
private static final String STROKE = "Stroke";
private static final String POINT_MARKER = "PointMarker";
protected SelectedSeriesStyle() {
super(IRenderableSeries.class);
configurePointMarker();
}
protected SelectedSeriesStyle(Class<IRenderableSeries> styleableObjectType) {
super(styleableObjectType);
configurePointMarker();
}
private void configurePointMarker() {
selectedPointMarker.setSize(10, 10);
selectedPointMarker.setFillStyle(new SolidBrushStyle(0xFFFF00DC));
selectedPointMarker.setStrokeStyle(new SolidPenStyle(ColorUtil.White, true, 1f, null));
}
@Override
protected void applyStyleInternal(IRenderableSeries renderableSeriesToStyle) {
putPropertyValue(renderableSeriesToStyle, STROKE, renderableSeriesToStyle.getStrokeStyle());
putPropertyValue(renderableSeriesToStyle, POINT_MARKER, renderableSeriesToStyle.getPointMarker());
renderableSeriesToStyle.setStrokeStyle(selectedStrokeStyle);
renderableSeriesToStyle.setPointMarker(selectedPointMarker);
}
@Override
protected void discardStyleInternal(IRenderableSeries renderableSeriesToStyle) {
renderableSeriesToStyle.setStrokeStyle(getPropertyValue(renderableSeriesToStyle, STROKE, PenStyle.class));
renderableSeriesToStyle.setPointMarker(getPropertyValue(renderableSeriesToStyle, POINT_MARKER, IPointMarker.class));
}
}
Now, create and add SeriesSelectionModifier onto your SciChartSurface:
// Assume a surface has been created and configured somewhere
// Create a SeriesSelectionModifier
final SeriesSelectionModifier seriesSelectionModifier = new SeriesSelectionModifier();
// Set a style which will be applied to a RenderableSeries when selected
seriesSelectionModifier.setSelectedSeriesStyle(new SelectedSeriesStyle());
// Add the modifier to the surface
surface.getChartModifiers().add(seriesSelectionModifier);
Note
To learn more about features available, please visit the Chart Modifier APIs article.
Note
To allow or prevent modifiers when inside a scroll view, please visit the isDisallowInterceptTouchEvent api. Example of the scroll view can be found on GitHub