Drop crosshair in linechart?
Hi,
I am investigating the sfCartesianChart and need to "drop" the crosshair in my SplineSeries. Ideally want it to always be visible at a certain position when the chart is created and when the user drags it it should move until the user release the mouse button and then stay in the new posistion. Is this possible to achieve?
BR
Hilma
Hi Hilma,
We have analyzed your query and would like to inform you that the ChartCrosshairBehavior is only visible during mouse movement on the Cartesian chart. This is the default behavior of the Crosshair. We can achieve your requirement using annotation. Unfortunately, WinUI SfCartesianChart does not have an annotation feature.
However, we can provide a workaround solution by using a custom template of a custom series to achieve the desired crosshair line and specifications. We will provide you with the sample on June 7th, 2023.
Best regards,
Nanthini Mahalingam.
We have analyzed your query and would like to inform you that we can only enable the crosshair feature after the chart is created. The crosshair will be visible when we move the mouse to a new position and release the mouse button. This can be achieved by implementing a custom crosshair behavior that inherits from the ChartCrossHairBehavior class. Here is a code snippet demonstrating the implementation:
[C#]
|
public class ChartCrossHairExt : ChartCrosshairBehavior {
protected override void OnPointerMoved(PointerRoutedEventArgs e) { base.OnPointerMoved(e); }
protected override void OnPointerPressed(PointerRoutedEventArgs e) { OnPointerMoved(e); }
protected override void OnPointerEntered(PointerRoutedEventArgs e) { OnPointerMoved(e); } } |
[Xaml]
|
… <chart:SfCartesianChart.CrosshairBehavior> <local:ChartCrossHairExt /> </chart:SfCartesianChart.CrosshairBehavior> … |
Please let us know if you need further assistance.
Attachment: SF_182717_5008186d.zip
Hi Nanthini,
And thanks for the code snippet. It does not address any of my problems though. If it is not possible to make the crosshair visible already when the chart is created I need it to at least stay in the position where it was when OnPointerReleased occured. Do I understand it correct that this is not possible to achieve?
BR
Hilma Maria
We have analyzed your query and would like to inform you that we can keep the crosshair at the pointer within the chart area only. When you press on the chart area, the crosshair will remain visible and stay in its position without any mouse movement. However, when you double click on the chart area, the pointer movement will resume.
Here is a code snippet demonstrating the implementation:
|
public class ChartCrossHairExt : ChartCrosshairBehavior { private bool isActivate = true;
public bool IsActivate { get { return isActivate; } set { isActivate = value; }
} protected override void OnPointerMoved(PointerRoutedEventArgs e) { // we invoke the base pointer moved to activate the mouse move. if (IsActivate) { base.OnPointerMoved(e); } }
protected override void OnPointerPressed(PointerRoutedEventArgs e) { // If you want cross hair at pointer press on the chart area, you can invoke pointer moved method. IsActivate = false; // In this case, cross hair stays at this position. if (IsActivate) { base.OnPointerMoved(e); } }
protected override void OnPointerEntered(PointerRoutedEventArgs e) { // If you want the cross hair at pointer enter on chart area, you can invoke the pointer moved method base.OnPointerMoved(e); }
protected override void OnDoubleTapped(DoubleTappedRoutedEventArgs e) { // When we double click on the chart area, mouse move activated again. base.OnDoubleTapped(e); IsActivate = true;
} } |
However, if the pointer exits from the chart area, the crosshair will disappear. This is the intended behavior of the crosshair.
If you are still experiencing any issues, please let us know. We are happy to assist you further.
Attachment: SF__182717_2226c97f.zip
Thanks for your reply. My need is that the crosshair is visible even when the pointer leaves the chart area, so this does not help. Also, that the crosshair does not move when the pointer is pressed instead of the opposite seems a bit backwards. I want to be able to drag the crosshair, that is how things usually are moved.
We have validated your query and would like to inform you that we can lock the crosshair at the specific pointer within the chart area only on point press. And for dragging the cross hair we have to press and move the pointer to any location within the chart area.
But the pointer will disappear when excited chart area on point pressed state. And reactivated on pointer press outside chart area and the lock is removed.
Here is the code snippet demonstrating the implementation and video for further reference.
|
public class ChartCrossHairExt : ChartCrosshairBehavior { private bool isActivate = true; private bool isReleased = true;
public bool IsActivate { get { return isActivate; } set { isActivate = value; }
}
protected override void OnPointerMoved(PointerRoutedEventArgs e) { // we invoke the base pointer moved to activate the cross hair. if (IsActivate) { base.OnPointerMoved(e); }
// we invoke this base pointer move when dragging the cross hair while pointer is pressed. if (!isReleased) { IsActivate = true; base.OnPointerMoved(e); }
}
protected override void OnPointerPressed(PointerRoutedEventArgs e) { // If you want cross hair at pointer press on the chart area, you can invoke this. isReleased = false; }
protected override void OnPointerReleased(PointerRoutedEventArgs e) { IsActivate = false; isReleased = true; }
protected override void OnPointerExited(PointerRoutedEventArgs e) { // when the cross hair is locked on pointer press the cross hair will not disappear // while exiting chart area and entering again the cross lock is removed. IsActivate = true; } } |
However, the crosshair will not disappear if dragged within the chart area. This is the above-mentioned behavior of the crosshair.
If you are still experiencing any issues, please let us know. We are happy to assist you further.
Regards,
Moneeshram D.
Attachment: SF_182717_e2e88bad.zip
- 6 Replies
- 3 Participants
-
HM Hilma Maria Tivegård
- Jun 2, 2023 11:22 AM UTC
- Jun 13, 2023 12:34 PM UTC