Skip to content

DataStreamer: Scroll view causes the plot to zoom out only (not zoom in) #3561

@hazenjaqdx3

Description

@hazenjaqdx3

Issue: When running a Datastream the Graph cannot be zoomed into further than the largest plotted data. Even though it has long dissapeared from the visible Data. (could there be a way to discharge the first data set in the DataStreamer Points arg?

ScottPlot Version: 5.0.23

Code Sample:

using ScottPlot;


namespace FinalFinal
{
    public partial class Form1 : Form
    {
        private BackgroundWorker UIWorker;

        public new List<double> dataX;
        public new List<double> dataY;
        public bool firstCon = false;

        public ScottPlot.Plottables.DataStreamer StreamX;
        public ScottPlot.Plottables.DataStreamer StreamY;

        public Int32 AverageX1;
        public Int32 AverageY1;

        public int DisplayX1 = 0;
        public int DisplayY1 = 0;

        public Form1()
        {
            InitializeComponent();

            if (firstCon == false)
            {
                initvoid();
            }

            UIWorker.DoWork += UIWorker_DoWork;
        }



        private void initvoid()
        {

            UIWorker = new BackgroundWorker();
            StreamX = formsPlot1.Plot.Add.DataStreamer(100000);
            StreamY = formsPlot1.Plot.Add.DataStreamer(100000);

            dataX = new List<double>();
            dataY = new List<double>();
            firstCon = true;

            StreamY.ViewScrollLeft();
            StreamX.ViewScrollLeft();
        }

        public void NewRealtimeData(Int32 X1, Int32 Y1)
        {
		// DISPLAYX1 AND DISPLAYY1 ARE JUST TWO VALUES WHICH I MEASURE WITH A SENSOR

            // Add X1 value to dataX list
            dataX.Add(DisplayX1);
            dataY.Add(DisplayY1);


            //If dataX list is full, add it to the Streamer
            if (dataX.Count >= 1000 && !UIWorker.IsBusy) // Adjust the threshold as needed
            {
                    UIWorker.RunWorkerAsync();
            }
        }

        private void UIWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (IsHandleCreated)
            {
                Invoke(new Action(() =>
                {
                    if (chkX.Checked)
                    {
                        StreamX.AddRange(dataX.ToArray()); // Add dataX list to Streamer
                    }

                    if (chkY.Checked)
                    {
                        StreamY.AddRange(dataY.ToArray());
                    }

                    formsPlot1.Refresh();
                }));
            }

            dataX.Clear(); // Clear dataX list after adding to Streamer
            dataY.Clear();
        }
    }
}

This is a gif of what I mean (please ignore the two lines "Alarm")
SVWyh

Also I have a question regarding this / similar :

I want to display the X/Y Points in a scatter Plot. How can I only show the 100 newest points and discard the older ones?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help WantedScott won't do this soon, but PRs from the community are welcome!⚠️ HIGH PRIORITY

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions