首页 > 解决方案 > 使用 Syncfusion.SfChart 将滑动添加到下一个手势

问题描述

目前在我的应用程序上,当用户选择他们的“症状”时,他们会被定向到详细信息页面,该页面显示他们的症状图表,其中包含来自所选症状的填充反馈数据。

他们是我可以添加滑动手势以允许用户滑动到下一个症状图表而无需返回主要症状页面并选择症状的一种方式。

目前这是我填充图表的方式:

public async Task GetSymptomFeedback(string id)
    {

        SymptomFeedbackData.Clear();
        symptomChart.Series.Clear();



        BusyIndicator.IsRunning = true;
        SymptomFeedbackData = await symptomsfeedbackmanager.getUserSymptomFeedback(id);



        foreach (var FeedbackItem in SymptomFeedbackData)
        {

            FeedbackItem.Idusersymptomid =  FeedbackItem.Id + ',' + FeedbackItem.Usersymptomid;


        }

        IEnumerable<SymptomFeedback> OrdreredFeedbackData =  SymptomFeedbackData.OrderBy(X => X.DateTime);

        LineSeries columnseries = new LineSeries
        {
            ItemsSource = OrdreredFeedbackData,
            XBindingPath =  "DateTime",
            YBindingPath = "Intensity",

            DataMarker = new ChartDataMarker
            {
                ShowLabel = true,
                ShowMarker = true,
                MarkerHeight = 5,
                MarkerWidth = 5,
                MarkerColor = Xamarin.Forms.Color.Purple
            }

        };






        BusyIndicator.IsRunning = false;



        symptomChart.PrimaryAxis.ShowTrackballInfo = true;


        if (columnseries.ItemsSource != null)
        {
            symptomChart.Series.Add(columnseries);
        }


        symptomChart.ChartBehaviors.Add(new ChartTrackballBehavior());

        //Sort Collection by datetime 



        SymptomsList.ItemsSource = OrdreredFeedbackData.Reverse(); 


    }

标签: xamarinxamarin.forms

解决方案


解决方案:

通过你的代码,我们可以看到你通过id症状查询数据。所以,我猜你id在转到detail pagefrom时将其作为参数传递main symptoms page

他们是我可以添加滑动手势以允许用户滑动到下一个症状图表而无需返回主要症状页面并选择症状的一种方式。

此外,您可以将array所有症状的 id 传递到详细信息页面。让我们将此数组命名为symptomIdArray.

然后将 a 添加SwipeGestureRecognizer到您的视图中。

    var DownSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Down };
    var UpSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Up };

    DownSwipeGesture.Swiped += OnSwiped;
    UpSwipeGesture.Swiped += OnSwiped;

    this.Content.GestureRecognizers.Add(DownSwipeGesture);
    this.Content.GestureRecognizers.Add(UpSwipeGesture);

在 中,你可以通过andOnSwiped获取lastnextid ,然后你可以选择重新加载当前页面或进入新页面滑动到下一个症状图表,代码如下:symptomIdArraycurrentID

  public Array symptomIdArray; // ids of all symptom

  public string currentID; // You selected id of current symptom

    void OnSwiped(object sender, SwipedEventArgs e)
            {

                int index = Array.IndexOf(symptomIdArray, currentID);

                switch (e.Direction)
                {
                    case SwipeDirection.Up:

                        if (index ==0)
                        {
                            //first one
                            break;
                        }

                        string lastID = (string)symptomIdArray.GetValue(index-1);

                        //1.You can refresh current page with lastId
                        GetSymptomFeedback(lastID);

                        //2.You can go to a new page with lastID ID and symptomIdArray
                        Navigation.PushAsync(new NewPage(lastID, symptomIdArray));

                        break;

                    case SwipeDirection.Down:
                        // Handle the swipe

                        if (index ==  symptomIdArray.Length-1)
                        {
                            //Last one,  no more

                            break;
                        }

                        string nextID = (string)symptomIdArray.GetValue(index+1);

                        //1.You can refresh current page with next currentID
                        GetSymptomFeedback(nextID);


                        //2.You can go to a new page with nextID ID and symptomIdArray
                        Navigation.PushAsync(new NewPage(nextID, symptomIdArray));

                        break;
                }
            }

更新:

添加SwipeGestureRecognizer

            SfChart chart = new SfChart();
            chart.Title.Text = "Chart";

            //Config chart....
            ...


            chart.Series.Add(series);
            this.Content = chart;

            var DownSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Down };
            var UpSwipeGesture = new SwipeGestureRecognizer { Direction = SwipeDirection.Up };

            DownSwipeGesture.Swiped += OnSwiped;
            UpSwipeGesture.Swiped += OnSwiped;

            chart.GestureRecognizers.Add(DownSwipeGesture);
            chart.GestureRecognizers.Add(UpSwipeGesture);

并且onSwipe

void OnSwiped(object sender, SwipedEventArgs e)
    {
            switch (e.Direction)
            {
                case SwipeDirection.Up:
                Console.WriteLine("up");
                    break;

                case SwipeDirection.Down:
                Console.WriteLine("down");

                break;
            }
    }

如果您有任何问题,请告诉我。


推荐阅读