I drawn a Line series using Syncfusion MAUI chart.
In this when I clicked on the series , It was considered as first click
Again I clicked , that was second click
我用SyncFusion毛伊图画了一个线列。在这个我点击这个系列的时候,它被认为是第一次点击,那就是第二次点击
I want to highlight series in between the two clicked points.
我想突出显示两个单击点之间的系列。
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:ChartInteractionBehaviour"
xmlns:chart="clr-namespace:Syncfusion.Maui.Charts;assembly=Syncfusion.Maui.Charts"
x:Class="ChartInteractionBehaviour.MainPage">
<chart:SfCartesianChart>
<chart:SfCartesianChart.BindingContext>
<local:ViewModel></local:ViewModel>
</chart:SfCartesianChart.BindingContext>
<chart:SfCartesianChart.XAxes>
<chart:DateTimeAxis></chart:DateTimeAxis>
</chart:SfCartesianChart.XAxes>
<chart:SfCartesianChart.YAxes >
<chart:NumericalAxis ></chart:NumericalAxis>
</chart:SfCartesianChart.YAxes>
<chart:LineSeries ItemsSource="{Binding Data}"
XBindingPath="Date"
YBindingPath="Amount"
></chart:LineSeries>
<chart:SfCartesianChart.InteractiveBehavior>
<local:ChartInteractiveExt></local:ChartInteractiveExt>
</chart:SfCartesianChart.InteractiveBehavior>
</chart:SfCartesianChart>
</ContentPage>
using Syncfusion.Maui.Charts;
using System.Collections.ObjectModel;
namespace ChartInteractionBehaviour
{
public class ChartInteractiveExt : ChartInteractiveBehavior
{
private float firstClickX = float.NaN;
private float firstClickY = float.NaN;
private float secondClickX = float.NaN;
private float secondClickY = float.NaN;
protected override void OnTouchUp(ChartBase chart, float pointX, float pointY)
{
base.OnTouchUp(chart, pointX, pointY);
if (float.IsNaN(firstClickX) || float.IsNaN(firstClickY))
{
firstClickX = pointX;
firstClickY = pointY;
}
else if (float.IsNaN(secondClickX) || float.IsNaN(secondClickY))
{
secondClickX = pointX;
secondClickY = pointY;
if (chart is Syncfusion.Maui.Charts.SfCartesianChart cartesianChart)
{
var pointX1 = cartesianChart.PointToValue(cartesianChart.XAxes[0],firstClickX,firstClickY);
var pointY1 = cartesianChart.PointToValue(cartesianChart.YAxes[0], firstClickX, firstClickY);
var pointX2 = cartesianChart.PointToValue(cartesianChart.XAxes[0], secondClickX, secondClickY);
var pointY2 = cartesianChart.PointToValue(cartesianChart.YAxes[0], secondClickX, secondClickY);
}
}
}
}
}
Expected output (Example)
预期输出(示例)
Please provide an idea or code to achieve this
请提供实现此目标的想法或代码
更多回答
优秀答案推荐
我是一名优秀的程序员,十分优秀!