Search Results for

    Show / Hide Table of Contents

    SeriesSelectionModifier

    SciChart features the SeriesSelectionModifier, which allows selection of the upmost RenderableSeries at a touch position:

    Series Selection Modifier

    Note

    Examples of the SeriesSelectionModifier usage can be found in the SciChart Android Examples Suite as well as on GitHub:

    • Native Example
    • Xamarin Example

    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:

    • Java
    • Java with Builders API
    • Kotlin
    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));
        }
    }
    
    class SelectedSeriesStyle extends StyleBase<IRenderableSeries> {
        private final PenStyle selectedStrokeStyle = sciChartBuilder.newPen()
                .withColor(ColorUtil.White)
                .withThickness(4f)
                .build();
    
        private final IPointMarker selectedPointMarker = sciChartBuilder.newPointMarker(new EllipsePointMarker())
                .withSize(10, 10)
                .withFill(0xFFFF00DC)
                .withStroke(ColorUtil.White, 1f)
                .build();
    
        private static final String STROKE = "Stroke";
        private static final String POINT_MARKER = "PointMarker";
    
        protected SelectedSeriesStyle() {
            super(IRenderableSeries.class);
        }
    
        protected SelectedSeriesStyle(Class<IRenderableSeries> styleableObjectType) {
            super(styleableObjectType);
        }
    
        @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));
        }
    }
    
    class SelectedSeriesStyle: StyleBase<IRenderableSeries>(IRenderableSeries::class.java) {
        private val STROKE = "Stroke"
        private val POINT_MARKER = "PointMarker"
    
        private val selectedStrokeStyle = SolidPenStyle(ColorUtil.White, true, 4f, null)
        private val selectedPointMarker: IPointMarker = EllipsePointMarker().apply {
            setSize(10, 10)
            fillStyle = SolidBrushStyle(0xFFFF00DC.toInt())
            strokeStyle = SolidPenStyle(ColorUtil.White, true, 1f, null)
        }
    
        override fun applyStyleInternal(renderableSeriesToStyle: IRenderableSeries) {
            putPropertyValue(renderableSeriesToStyle, STROKE, renderableSeriesToStyle.strokeStyle);
            putPropertyValue(renderableSeriesToStyle, POINT_MARKER, renderableSeriesToStyle.pointMarker);
    
            renderableSeriesToStyle.strokeStyle = selectedStrokeStyle
            renderableSeriesToStyle.pointMarker = selectedPointMarker
        }
    
        override fun discardStyleInternal(renderableSeriesToStyle: IRenderableSeries) {
            renderableSeriesToStyle.strokeStyle = getPropertyValue(renderableSeriesToStyle, STROKE, PenStyle::class.java)
            renderableSeriesToStyle.pointMarker = getPropertyValue(renderableSeriesToStyle, POINT_MARKER, IPointMarker::class.java)
        }
    }
    

    Now, create and add SeriesSelectionModifier onto your SciChartSurface:

    • Java
    • Java with Builders API
    • Kotlin
    // 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);
    
    // 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);
    
    // Assume a surface has been created and configured somewhere
    // Create a SeriesSelectionModifier
    val seriesSelectionModifier = SeriesSelectionModifier()
    
    // Set a style which will be applied to a RenderableSeries when selected
    seriesSelectionModifier.selectedSeriesStyle = SelectedSeriesStyle()
    
    // Add the modifier to the surface
    surface.chartModifiers.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

    Back to top © 2011-2025 SciChart. All rights reserved. | sitemap.xml