Skip to content

DataStreamer ContinuouslyAutoscale #3732

@rubenslkirchner

Description

@rubenslkirchner

Issue: If the ContinuouslyAutoscale is True some chart components get lost (Markers for example)

ScottPlot Version: 5.0.28

Code Sample: See http://scottplot.net/faq/repro/ for tips about creating reproducible code samples

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ScottPlot;
using ScottPlot.Plottables;
using ScottPlot.WPF;

namespace trips.playback.plotters.scottplot;

public class RealTimeChart : ITestScenario
{
    private List<Task> _tasks;

    public RealTimeChart(WpfPlot wpfplot1, WpfPlot wpfplot2)
    {
        wpfplot1.Plot.Axes.AutoScale();
        wpfplot2.Plot.Axes.AutoScale();

        Task.Run(() => DoWork(wpfplot1));
    }

    private Task DoWork(WpfPlot plot)
    {
        const int points = 1000;

        var streamer = plot.Plot.Add.DataStreamer(points);
        //streamer.ContinuouslyAutoscale = true; // UNCOMMENT THIS LINE AND THE MARKER POSITION (X) GOES CRAZY. 
        streamer.ViewScrollLeft();

        int x = 0;
        Marker? m1 = null;

        while (true)
        {
            double y = Math.Sin(x);
            streamer.Add(y);

            if (m1 == null)
            {
                m1 = plot.Plot.Add.Marker(points, Math.Sin(x), MarkerShape.FilledCircle, 10, Colors.Black);
            }
            else
            {
                if (m1.Location.X > 0)
                {
                    m1.Location = new Coordinates(m1.Location.X - 1, m1.Location.Y);
                }
                else
                {
                    m1.Location = new Coordinates(points, y);
                }
            }

            Thread.Sleep(10);
            plot.Refresh();
            x++;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions