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