Pre loader

enable and disable AnnotationCreationListener with toggle button

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

Hi,

I’d like to enable AnnotationCreationListener with a toggle button pressed down, and disable it with the button released. It’s different from the Android sample code in Create Annotation Dynamically. I have a few questions when I’m trying to code. I’m not sure if my approach is on the right track. Please advise, thanks.

// insert button listener
    insertAnnotationButton = findViewById(R.id.annotationInsertButton);
    insertAnnotationButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // TODO: add chartmodifier/annotationCreationModifier when button pressed down
            if (insertAnnotationButton.isChecked()) {
                annotationCreationModifier.setAnnotationType(???); // how to set type to vertical line annotation?
                DefaultAnnotationFactory annotationFactory = new DefaultAnnotationFactory();
                annotationFactory.setFactoryForAnnotationType(DefaultAnnotationFactory.VERTICAL_LINE_ANNOTATION, new IAnnotationFactory() {
                    @NonNull
                    @Override
                    public IAnnotation createAnnotation(@NonNull ISciChartSurface parentSurface, int annotationType) {
                        return sciChartBuilder.newVerticalLineAnnotation().withIsEditable(true).withStroke(1, White).withVerticalGravity(Gravity.FILL_VERTICAL).build();
                    }
                });
                annotationCreationModifier.setAnnotationFactory(annotationFactory);
                annotationCreationModifier.setAnnotationCreationListener(new OnAnnotationCreatedListener() {
                    @Override
                    public void onAnnotationCreated(IAnnotation iAnnotation) {
                        // how to get X coordinate of the annotation and update my annotation variable

                    }
                });
                ecmSurface.getChartModifiers().add(sciChartBuilder.newModifierGroup().withModifier(annotationCreationModifier)..build());
            } else {
                // how to remove annotationCreationModifier from ChartModifiers?
                ecmSurface.getChartModifiers().remove(???);
            }
        }
    });
Version
3.1.0.4341
  • You must to post comments
0
0

Hi there,

You can enable/disable ChartModifiers using IsEnabled property.

 annotationCreationModifier.setIsEnabled(false);

Best regards,
Yura

  • You must to post comments
0
0

Hi Yura,
I’ve managed to make it work with your way. Thanks.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies