Axis click

6 posts, 0 answers
  1. Flemming
    Flemming avatar
    12 posts
    Member since:
    Aug 2016

    Posted 16 Sep Link to this post

    I have a RadCartesianChart with a vertical linear axis.

    I want to be able to click on the axis and show a dialog.

    I have got it working on the MouseLeftButtonUp event – but it only triggers when I click the labels – and not the background. I have tried to style the axis – but with no luck. 

     

    /Flemming 

  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 20 Sep Link to this post

    Hi Flemming,

    Most of the chartview elements use a Canvas to add visuals in and render. Because of how the visual tree is structured, all elements end up in the top left corner with a size of 0. So unless you click an element that is the child of the axis, you cannot determine that the axis was clicked.

    You can use the position of the clicked event to see where the chart was clicked and if it is to the left of the plot area - then the left axis was clicked. You can use the PlotAreaClip property of the chart to do that check:

    private void chart1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
     Point pos = e.GetPosition(this.chart1);
     double plotAreaLeft = this.chart1.PlotAreaClip.X + this.chart1.PanOffset.X;
     double plotAreaRight = this.chart1.PlotAreaClip.Right + this.chart1.PanOffset.X;
     
     if (pos.X < plotAreaLeft)
     {
      // if there is a left axis, it was clicked
     }
     else if (plotAreaRight < pos.X)
     {
      // if there is a right axis, it was clicked
     }
    }

    This method needs to be refined because it does not take into account where vertically the click happened and may be it happened outside the axis, you can improve the method if you decide to use this approach. In case you have multiple axes on one side, this approach will not suffice. Let us know if this is the case and we can work it out.

    Regards,
    Petar Marchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Flemming
    Flemming avatar
    12 posts
    Member since:
    Aug 2016

    Posted 22 Sep in reply to Petar Marchev Link to this post

    Thank you for the explanation. 

    Wouldn't it be possible to add an extra transparent element behind the axis to make it possible to hit test it?  You must now the size of whole axis element internally? 

    Or expose the axis size so I can do some calculations on the mouse position. 

    /Flemming

  5. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 26 Sep Link to this post

    Hello,

    As I explained earlier, currently you can use the plot area size to determine whether or not you have clicked on the axis. Let us know if you have any other questions.

    Regards,
    Petar Marchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Flemming
    Flemming avatar
    12 posts
    Member since:
    Aug 2016

    Posted 26 Sep in reply to Petar Marchev Link to this post

    I understood what you explained earlier – but as you yourself stated – it was not a perfect solution – that had problems with multiple axes on one side.

    I was under the impression that you wanted to find ways to improve your product and it would seem that the solution I presented, could solve the issue with a small investment from your side.

    /Flemming Rosenbrandt

  7. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 29 Sep Link to this post

    Hello Flemming,

    Thank for your feedback. Your request seems reasonable so we logged a feature request in our feedback portal. There you can follow the item's status. You can also find your Telerik points updated.

    Regards,
    Martin
    Telerik by Progress
    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 WPF is Visual Studio 2017 Ready