Giter Site home page Giter Site logo

syncfusionexamples / how-to-add-multiple-trackball-in-xamarin.android-chart Goto Github PK

View Code? Open in Web Editor NEW
0.0 6.0 1.0 104 KB

This example demonstrates how to add multiple trackball in Xamarin.Android Chart

C# 100.00%
chart charts trackball xamarin xamarin-android multi-trackball

how-to-add-multiple-trackball-in-xamarin.android-chart's Introduction

# How to add the multiple trackball in Xamarin.Android chart (SfChart)?

SfChart allows you add multiple trackballs to a single chart and drag them independently to view the information of different data points at the same time.

The following steps describe how to add multiple trackballs to SfChart.

Step 1: Create a custom ChartTrackballBehaviorExt class, which is inherited from ChartTrackballBehavior.

public class ChartTrackballBehaviorExt : ChartTrackballBehavior
{
}

Step 2: Create an instance of ChartTrackballBehaviorExt and add it to the Behaviors collection.

ChartTrackballBehaviorExt trackballBehavior1 = new ChartTrackballBehaviorExt();
ChartTrackballBehaviorExt trackballBehavior2 = new ChartTrackballBehaviorExt();
chart.Behaviors.Add(trackballBehavior1);
chart.Behaviors.Add(trackballBehavior2);

Step 3: Activate the multiple trackballs at load time using the Show method.

public override void OnAttachedToWindow()
{
    base.OnAttachedToWindow();
    
    Task.Run(async () =>
    {
        await ShowTrackball();
    });
}
 
async Task ShowTrackball()
{
    Task.Delay(1000).Wait();
 
    trackballBehavior1.Show(pointX, pointY);
    trackballBehavior2.Show(pointX, pointY);
}

Step 4: Set ActivationMode to None to restrict the default movement of the trackball behavior.

trackballBehavior1.ActivationMode = ChartTrackballActivationMode.None;
trackballBehavior2.ActivationMode = ChartTrackballActivationMode.None;

Step 5: Interact with multiple trackballs by overriding the touch methods of ChartTrackballBehavior class and the HitTest method. The HitTest method is used to find the trackball that is currently activated by user.

public class ChartTrackballBehaviorExt : ChartTrackballBehavior
{
    bool isActivated= false;
 
    protected override void OnTouchDown(float pointX, float pointY)
    {
        if (HitTest(pointX, pointY))
        {
            isActivated= true;
            base.OnTouchDown(pointX, pointY);
        }
    }
 
    protected override void OnTouchMove(float pointX, float pointY)
    {
        if (isActivated)
        {
            Show(pointX, pointY);
            base.OnTouchMove(pointX, pointY);
        }
    }
 
    protected override void OnTouchUp(float pointX, float pointY)
    {
        isActivated= false;
    }
}

Step 6: Tap and drag each trackball separately to view the data points at different positions simultaneously.

Output:

Multiple trackball in Xamarin.Android Chart

KB article - How to add the multiple trackball in Xamarin.Android chart

Troubleshooting

Path too long exception

If you are facing path too long exception when building this example project, close Visual Studio and rename the repository to short and build the project.

how-to-add-multiple-trackball-in-xamarin.android-chart's People

Contributors

devakumard avatar karthikeyanvis avatar muneeshkumarg avatar sarubala20 avatar vinothkumar-ganesan avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

lunawatkins01

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.