Multiple axis for ChartCrosshairBehavior in RadCartesianChart

6 posts, 0 answers
  1. Valentin
    Valentin avatar
    73 posts
    Member since:
    Mar 2016

    Posted 04 May Link to this post

    Hello,

     

    I'm using a ChartCrosshairBehavior in my RadCartesianChart.

    Currently, for the CrossHair Control, the target axis is a left-axis (by default). => picture "one"

     

    I want to know if is it possible to target the right axis, and if yes, how can i do this ? (picture "two")

     

    This my code :

    01.<telerik:ChartCrosshairBehavior x:Name="chartCross" PositionChanged="chartCross_PositionChanged"                                         HorizontalLineLabelVisibility="Hidden"                                                                   HorizontalLineVisibility="Hidden"                                                                        VerticalLineLabelVisibility="Hidden"                                                                     VerticalLineVisibility="Hidden">                                            <telerik:ChartCrosshairBehavior.HorizontalLineLabelDefinition>                                                <telerik:ChartAnnotationLabelDefinition Format="{}{0:N1}" Location="Left" />                                      </telerik:ChartCrosshairBehavior.HorizontalLineLabelDefinition>                            </telerik:ChartCrosshairBehavior>

     

     

    Thank you !

     

    Valentin.

     

     

  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 05 May Link to this post

    Hello Valentin,

    Currently all the behaviors, including the crosshair behavior, work with the main axes only. The main axes are the ones that are set for the HorizontalAxis and VerticalAxis properties of the chart.

    If you need to put a label for an additional axis, you can do this manually. You can place a Canvas over the chart and put some custom label in the Canvas. Then in the PositionChanged event handler of the crosshair you can update the position of the custom label and its content via the conversion api of the chart (namely the ConvertPointToData method).

    Regards,
    Petar Marchev
    Telerik
    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. Valentin
    Valentin avatar
    73 posts
    Member since:
    Mar 2016

    Posted 09 May in reply to Petar Marchev Link to this post

    Hello,

     

    Thanks for your help.

    I do not arrive to get the right axis point in the CrossHair_positionChanged. This line :

    var ptToDt = chartVariables.ConvertPointToData(((ChartCrosshairPositionChangedEventArgs)e).Position);

    is focused on the left axis..

  5. Valentin
    Valentin avatar
    73 posts
    Member since:
    Mar 2016

    Posted 09 May Link to this post

    Hello,

     

    I've got the solution for the persons who need it :

    CartesianAxis selectedAxis = chartVariable_FindSelectedAxis();
     
    //Get the point where is the mouse
    Point laPosition = e.GetPosition(chartVariables);
     
    //Convert Point in Data, with the axis parameters
    DataTuple pointInData = this.chartVariables.ConvertPointToData(laPosition, this.chartVariables.HorizontalAxis, selectedAxis);

     

    This code turn on in chartVariables_MouseMove(object sender, MouseEventArgs e), not in crossHair_PositionChanged(object sender, ChartCrosshairPositionChangedEventArgs e).

     

    Thank you for your help !

  6. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 10 May Link to this post

    Hello Valentin,

    I am not sure why you were unable to get it working with the PositionChanged event. I tried this piece of code and all seems to work properly:
    private void ChartCrosshairBehavior_PositionChanged(object sender, ChartCrosshairPositionChangedEventArgs e)
    {
      var data = this.chart1.ConvertPointToData(e.Position, this.chart1.HorizontalAxis, this.rightAxis1);
      this.tb1.Text = "" + data.FirstValue + ", " + data.SecondValue;
    }

    Regards,
    Petar Marchev
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  7. Valentin
    Valentin avatar
    73 posts
    Member since:
    Mar 2016

    Posted 10 May in reply to Petar Marchev Link to this post

    Hello,

     

    I tried your code but it cannot working in my program. In my chart, the right axis is not always existing, so, I havn't got a "rightAxis1" control (or equivalent).

     

    Do you want my chartVariable_FindSelectedAxis() method ? It working just for my program, but it can give you an idea of how i get the selected axis.

     

    Regards,

    Valentin.

Back to Top
UI for WPF is Visual Studio 2017 Ready