Two color line series with dynamic limit

LijoCJLijoCJ USMember ✭✭

I created following two color line series in Xamarin Forms using OxyPlot, by setting a Limit value of 130. My actual requirement is that the color change should happen based on another series (areaSeries1 - drawn in yellow color area series). Any portion of the twocolorseries that is inside the yellow areaSeries1 should be shown in red color. And anything above that should be in white color. How to do it in Xamarin Forms using OxyPlot?

    public PlotModel CreateMyChart()
    {
        PlotModel plotModel1 = new PlotModel { Title = "Area" };
        var valueAxisX = new LinearAxis
        {
            Position = AxisPosition.Bottom,
            AxislineColor = OxyColors.White,
            TicklineColor = OxyColors.White,
            TextColor = OxyColors.White,
            FontSize = 12,
            IsZoomEnabled = false,
            IsPanEnabled = false
        };

        var valueAxisY = new LinearAxis
        {
            Position = AxisPosition.Left,
            Minimum = 100,
            AxislineColor = OxyColors.White,
            TicklineColor = OxyColors.White,
            TextColor = OxyColors.White,
            FontSize = 12,
            IsZoomEnabled = false,
            IsPanEnabled = false,
            MajorGridlineStyle = LineStyle.Dash,
            MajorGridlineColor = OxyColors.Gray
        };

        plotModel1.Axes.Add(valueAxisX);
        plotModel1.Axes.Add(valueAxisY);

        plotModel1.DefaultColors = new List<OxyColor>
        {
            OxyColors.Yellow,
            OxyColors.Cyan,
            OxyColors.Teal 
        };

        AreaSeries areaSeries1 = new AreaSeries
        {
            MarkerType = MarkerType.Circle,
            MarkerSize = 2,
            StrokeThickness = 2,
            Smooth = true
        };
        areaSeries1.Points.Add(new DataPoint(0, 127));
        areaSeries1.Points.Add(new DataPoint(10, 132));
        areaSeries1.Points.Add(new DataPoint(20, 130));



        TwoColorLineSeries twocolorseries = new TwoColorLineSeries
        {
            MarkerType = MarkerType.Circle,
            Color = OxyColors.White,
            Color2 = OxyColors.Red,
            Limit = 130,
            MarkerSize = 5,
            MarkerStrokeThickness = 5,
            MarkerFill = OxyColors.Red,
            MarkerStroke = OxyColors.Yellow,
            StrokeThickness = 5,
            Smooth = true,
        };
        twocolorseries.Points.Add(new DataPoint(0, 120));
        twocolorseries.Points.Add(new DataPoint(2, 125));
        twocolorseries.Points.Add(new DataPoint(6, 145));
        twocolorseries.Points.Add(new DataPoint(15, 130));
        twocolorseries.Points.Add(new DataPoint(17, 110));
        twocolorseries.Points.Add(new DataPoint(20, 140));

        plotModel1.Series.Add(areaSeries1);
        plotModel1.Series.Add(twocolorseries);



        return plotModel1;

    }
Tagged:
Sign In or Register to comment.