This is a migrated thread and some comments may be shown as answers.

Multiple axis for ChartCrosshairBehavior in RadCartesianChart

5 Answers 159 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Valentin
Top achievements
Rank 1
Iron
Iron
Valentin asked on 04 May 2016, 08:52 AM

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.

 

 

5 Answers, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 05 May 2016, 08:00 AM
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.
0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 09 May 2016, 09:38 AM

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..

0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 09 May 2016, 03:57 PM

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 !

0
Petar Marchev
Telerik team
answered on 10 May 2016, 08:00 AM
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.
0
Valentin
Top achievements
Rank 1
Iron
Iron
answered on 10 May 2016, 08:29 AM

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.

Tags
Chart
Asked by
Valentin
Top achievements
Rank 1
Iron
Iron
Answers by
Petar Marchev
Telerik team
Valentin
Top achievements
Rank 1
Iron
Iron
Share this question
or