Programatically move and show trackball

6 posts, 1 answers
  1. Deamon
    Deamon avatar
    8 posts
    Member since:
    Nov 2012

    Posted 16 Nov 2012 Link to this post

    I have 2 ChartView's with trackballs.  I want to mouse over one 1 graph that shows the trackball and programatically position the second graphs trackball dependent upon where I am mouse overing on the the first graph.  What approach should I take? 

    Thanks
  2. Answer
    Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 21 Nov 2012 Link to this post

    Hello Deamon,

    Thank you for writing.

    Please, find attached an example project where I have implemented a similar case to yours. The solution is to create a custom chart view control inheriting from RadChartView and allow mouse move events to be fired through code. This starts the internal mechanism of the trackball and the two trackballs move together.

    I hope this will be useful. Should you have further questions, I would be glad to help.
     
    Regards,
    Ivan Petrov
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Deamon
    Deamon avatar
    8 posts
    Member since:
    Nov 2012

    Posted 21 Nov 2012 Link to this post

    This worked for me with a modification.  My x's don't match due to padding on the second graph.  I move by x + offset and it works like a charm, thanks.

    I tried to add the same thing so that movement of the send trackball moves the first, but ran into weird issues since the first trackball then proceeds to move the second and so forth.

    G
  5. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 26 Nov 2012 Link to this post

    Hello Deamon,

    Thank you for writing back.

    I am glad my previous post was helpful. To overcome the issue where the two trackballs would move each other until a StackOverflow exception is thrown, you can make the following change to the code:
    private ChartTrackballController leftTrackball;
    private ChartTrackballController rightTrackball;
     
    private void trackball_LocationChanged(object sender, LocationChangedEventArgs e)
    {
        this.leftTrackball.LocationChanged -= trackball_LocationChanged;
        this.rightTrackball.LocationChanged -= trackball_LocationChanged;
     
        if (sender == this.leftTrackball)
        {
            this.radChartView2.MoveTrackball(e.Location);
        }
        else if (sender == this.rightTrackball)
        {
            this.radChartView1.MoveTrackball(e.Location);
        }
     
        this.leftTrackball.LocationChanged += trackball_LocationChanged;
        this.rightTrackball.LocationChanged += trackball_LocationChanged;
    }

    I have moved the trackballs to be fields of the form. Their LocationChanged event is handled in one method. You will have to again calculate the proper location based on the offset(s) in the charts.

    I hope this will help. Feel free to write back with any further questions.

    Greetings,
    Ivan Petrov
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  6. Sudha
    Sudha avatar
    1 posts
    Member since:
    Mar 2016

    Posted 18 May Link to this post

    My requirement is slightly different. I have a RadChartView and RadGridView that displays the chart data in a tabular form. When the TrackBall location changes I change the row selection in the RadGridView. What I dont have right now is when the RadGridView row changes move the trackball selection to the desired position in RadChartView.

    Could anyone help me achiveve this?

    Thank you so much!

    Sudha

  7. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 19 May Link to this post

    Hello Sudha,

    Thank you for writing.

    Please refer to the following code snippet demonstrating how to achieve the illustrated result from the attached gif file:
    private void Form1_Load(object sender, EventArgs e)
    {
        this.productsTableAdapter.Fill(this.nwindDataSet.Products);
     
        this.radGridView1.DataSource = this.productsBindingSource;
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
     
        LineSeries lineSeria = new LineSeries();
        radChartView1.Series.Add(lineSeria);
        lineSeria.ValueMember = "UnitPrice";
        lineSeria.CategoryMember = "ProductName";
        lineSeria.DataSource = this.productsBindingSource;
     
        CategoricalAxis horizontalAxis = lineSeria.HorizontalAxis as CategoricalAxis;
        if (horizontalAxis != null)
        {
            horizontalAxis.LabelFitMode = AxisLabelFitMode.MultiLine;
        }
     
        trackBallController = new CustomChartTrackballController();
        radChartView1.Controllers.Add(trackBallController);
     
        this.radGridView1.CurrentRowChanged += radGridView1_CurrentRowChanged;
    }
     
    private void radGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
    {
        if (e.CurrentRow != null && e.CurrentRow.Index>-1)
        {
            CategoricalDataPoint point = this.radChartView1.Series[0].DataPoints[e.CurrentRow.Index] as CategoricalDataPoint;
            trackBallController.MoveTrackballToCoordinates(new PointF((float)point.LayoutSlot.Location.X, (float)point.LayoutSlot.Location.Y));
            this.radChartView1.Invalidate();
        }
    }
     
    CustomChartTrackballController trackBallController = null;
    public class CustomChartTrackballController : ChartTrackballController
    {
        public void MoveTrackballToCoordinates(PointF point)
        {
            this.MoveTrackball(point);
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.

     Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready