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

Axis click

5 Answers 48 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Flemming
Top achievements
Rank 1
Flemming asked on 16 Sep 2016, 09:25 AM

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 

5 Answers, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 20 Sep 2016, 11:01 AM
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.
0
Flemming
Top achievements
Rank 1
answered on 22 Sep 2016, 07:49 AM

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

0
Petar Marchev
Telerik team
answered on 26 Sep 2016, 07:22 AM
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.
0
Flemming
Top achievements
Rank 1
answered on 26 Sep 2016, 08:46 AM

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

0
Martin Ivanov
Telerik team
answered on 29 Sep 2016, 08:35 AM
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.
Tags
ChartView
Asked by
Flemming
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Flemming
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or