Line Chart with OxyPlot.Xamarin.Forms show track on point tabbed

notarealgrealnotarealgreal Member ✭✭
edited January 30 in Xamarin University

Hi, I'm working with a line chart with the OxyPlot.Xamarin.Forms plugin, this is the plot function:
public PlotModel GetLineChart()
{

        OnPropertyChanged("GraphModel");

        var model = new PlotModel
        {
            LegendPlacement = LegendPlacement.Outside,
            LegendPosition = LegendPosition.BottomCenter,
            LegendOrientation = LegendOrientation.Horizontal,
            LegendBorderThickness = 0
        };
        model.PlotType = PlotType.XY;
        model.InvalidatePlot(false);

        Dictionary<string, List<Prices>> values = HistoricData[Selected.ProductId];


        int colorIndex = 0;
        List<string> x_names = new List<string>();

        foreach (var item in values.Keys)
        {

            if (item.ToUpper() == Selected.ProductName) { SelectedIndex = colorIndex; }
            var lineSeries = new LineSeries()
            {
                Title = item,
                MarkerType = MarkerType.Circle,
                //TrackerFormatString = "X={2},\nY={4}",
                CanTrackerInterpolatePoints = false
                //LabelPlacement = LabelPlacement.Inside
                //LabelFormatString = "{0}"
            };
            lineSeries.MarkerResolution = 3;
            lineSeries.MarkerFill = OxyPlot.OxyColor.Parse(SubCategoriesViewModel.AvailableColors[colorIndex]);
            lineSeries.MarkerStroke = OxyPlot.OxyColor.Parse(SubCategoriesViewModel.AvailableColors[colorIndex]);
            lineSeries.MarkerSize = 3;

            var points = new List<DataPoint>();


            lineSeries.Color = OxyColor.Parse(SubCategoriesViewModel.AvailableColors[colorIndex]);

            foreach (var price in values[item])
            {
                points.Add(new DataPoint(price.Week+price.Year, price.Price));           
            }

            if (ButtonsVisibility.Count == 0)
            {
                lineSeries.IsVisible = (Selected.ProductName == item.ToUpper()) ? true : false;
            }
            else
            {
                lineSeries.IsVisible = ButtonsVisibility[colorIndex];
            }


            lineSeries.ItemsSource = points;
            lineSeries.MarkerType = OxyPlot.MarkerType.Circle;


            lineSeries.TrackerFormatString = "X={2},\nY={4}";
            lineSeries.TextColor = OxyPlot.OxyColor.Parse(SubCategoriesViewModel.AvailableColors[colorIndex]);

            model.Series.Add(lineSeries);
            colorIndex++;
        }

        NumButtons = colorIndex;

        LinearAxis yaxis = new LinearAxis();
        yaxis.Position = AxisPosition.Left;
        yaxis.MajorGridlineStyle = LineStyle.Dot;
        model.Axes.Add(yaxis);

        LineChart = model;
        OnPropertyChanged("GraphModel");
        return LineChart;

    }
}

Then in the LineChart.xaml.cs file:
protected async override void OnAppearing()
{
await _viewModel.LinearViewModel.GetSubCategoryHistoricWeekPrices(App.ViewModel.LoginViewModel.SesionToken, FROM_DATE, TO_DATE);

    Plot.Model = _viewModel.LinearViewModel.GetLineChart();
        PlotController controller = new PlotController();
        controller.UnbindAll();
        controller.BindTouchDown(PlotCommands.PointsOnlyTrackTouch);
        Plot.Controller = controller;

        AddButtons();
    }

My problem is that when the user taps one point of the line series, I want to display the track of that point, something like:
Track info of a point

But in my case, after a tap doesn't appear any track, I think that the problem is in the controller bindings on the OnAppearing method but I don't know which binding I should in the controller to show the track, any suggestion?

Sign In or Register to comment.