Search code examples
wpfoxyplot

Hide some points in Oxyplot Line series


I need to show/hide some data points in oxyplot line series. Is it possible? Though some markers are invisible, the line should go through the invisible markers.


Solution

  • You could make use of two series to achieve this. The first one would draw the complete points (and line) without the marker. The second series would draw the visible points(with marker,but with line style set to none). For Example

     DataPoint[] points = new DataPoint[]
            {
                new DataPoint(1,12),
                new DataPoint(2,10),
                new DataPoint(3,9),
                new DataPoint(4,13),
                new DataPoint(5,14),
                new DataPoint(6,10)
            };
            var seriesComplete = new OxyPlot.Series.LineSeries();
    
            seriesComplete.Points.AddRange(points);
    
    
            var seriesVisible = new OxyPlot.Series.LineSeries();
            seriesVisible.Points.AddRange(points.Where(x => x.Y % 2 == 0));
            seriesVisible.MarkerFill = OxyColors.Blue;
            seriesVisible.MarkerType = MarkerType.Circle;
            seriesVisible.MarkerSize = 10;
            seriesVisible.LineStyle = LineStyle.None;
    
            this.MyModel.Series.Add(seriesComplete);
            this.MyModel.Series.Add(seriesVisible);
    

    Result is attached as imageenter image description here