0

Is there a way to tell oxyplot to use the x value as the connect/draw order for a line plot instead of the order that the points are added?

Let's assume I have this huge amount of points (2Gb in RAM) of a time series. At a higher level I am only adding a small percentage of those points and as the user zooms into a more specific region I add more points to the series so he can see more detail. Almost like a texture mimap. I can add all the points at once but then oxy becomes really slow when I tries to render all those points in a single window in WPF Maybe there is another solution here?

The problem that I am facing is that oxy draws a line from the last point in the graph to the first one of the new batch because it uses the series points list as the draw order not the X value. Is there a way to change this?

Here is a tiny example based on the 'WPF Simple Example':

        var plotModel = new PlotModel { Title = "Simple example", Subtitle = "using OxyPlot" };
        var timeAxis = new DateTimeAxis
        {
            Position = AxisPosition.Bottom,
            StringFormat = "hh:mm:ss",
        };
        plotModel.Axes.Add(timeAxis);

        var now = DateTime.UtcNow;

        // Create two line series (markers are hidden by default)
        var series1 = new LineSeries { Title = "Series 1", MarkerType = MarkerType.Circle };
        series1.Points.Add(new DataPoint(DateTimeAxis.ToDouble(now), 5));
        series1.Points.Add(new DataPoint(DateTimeAxis.ToDouble(now.AddMinutes(1)), 7));
        series1.Points.Add(new DataPoint(DateTimeAxis.ToDouble(now.AddMinutes(2)), 8));
        series1.Points.Add(new DataPoint(DateTimeAxis.ToDouble(now.AddMinutes(0.5)), 10));

        // Add the series to the plot model
        plotModel.Series.Add(series1);
        // Set the Model property, the INotifyPropertyChanged event will make the WPF Plot control update its content
        this.Model = plotModel;

Here is the output, note that the line draws "back in time": Output

Is there a solution that does not involves me sorting the points list (not even sure if this works)? Or maybe I am doing this extra points for details thing completely wrong :)

  • 1
    If you really need to add points out of order, then use a **sorted collection** and bind it to your `LineSeries`, MVVM style, rather than adding points directly to it. – jsanalytics Nov 16 '17 at 09:16
  • And if you _really_ need to add a huge amount of points to your series, first add them to a collection in your view model and then bind to it dynamically. – jsanalytics Nov 16 '17 at 09:22
  • Hey Jstreet thankj you! For some reason I forgot about SortedSet, List, Dictionary... I am going to answer the question tonight! – Juliano Franz Nov 16 '17 at 22:57
  • Oh and as o following the MVVM style I am, I've decided not to in the example for simplicity. About the large amount of points I am dynamically loading them from the DB based on what is the users current view. Are you suggesting me to pre load everything first? – Juliano Franz Nov 16 '17 at 22:59
  • Well, _load everything_ depends on the context... what I am suggesting is that, let's say, at any moment, you need to load **N** points (you can call **N** everything here in this context), and if this is a number large enough to cause the chart to lag, then yes, load all points first and then bind. – jsanalytics Nov 17 '17 at 00:23

0 Answers0