Skip to content

How to print a single data live? #764

@saklanmazozgur

Description

@saklanmazozgur

Hello,

There is a refreshing data every 100 ms. I want to show this data on the graph but I was not successful. I can't see any data on the chart when I write it as below. I would be happy if you could help.

System.Drawing.Color color = System.Drawing.Color.FromArgb(255, 139, 26, 26);
double[] angle1Array = new double[1];

private void DispactherTimer_Tick(object sender, EventArgs e)
        {
            try
            {
                    angle1Array[0] = Convert.ToDouble(angle1.Text);
                    dateTime = dateTime.AddMilliseconds(100);
                    Angle_Angle1_Graphic.plt.PlotSignal(angle1Array, 864000, xOffset: dateTime.ToOADate(), color: color, markerSize: 5);
                    Angle_Angle1_Graphic.plt.AxisAuto();
                    Angle_Angle1_Graphic.Render();
            }
            catch
            {

            }
        }

I tested the growing data in the demo in my own application, I am having a similar problem. Could there be a situation about the version difference?

Version 4.0.48

Growing Data Code

    public partial class MainWindow : Window
    {
        public double[] data = new double[100_000];
        int nextDataIndex = 1;

        PlottableSignal signalPlot;
        Random rand = new Random(0);

        private DispatcherTimer _updateDataTimer;
        private DispatcherTimer _renderTimer;

        public MainWindow()
        {
            InitializeComponent();

            var signalPlot = wpfPlot1.plt.PlotSignal(data);
            wpfPlot1.plt.YLabel("Value");
            wpfPlot1.plt.XLabel("Sample Number");

            _updateDataTimer = new DispatcherTimer();
            _updateDataTimer.Interval = TimeSpan.FromMilliseconds(1);
            _updateDataTimer.Tick += UpdateData;
            _updateDataTimer.Start();

            _renderTimer = new DispatcherTimer();
            _renderTimer.Interval = TimeSpan.FromMilliseconds(20);
            _renderTimer.Tick += Render;
            _renderTimer.Start();

            Closed += (sender, args) =>
            {
                _updateDataTimer?.Stop();
                _renderTimer?.Stop();
            };
        }


        void UpdateData(object sender, EventArgs e)
        {
            if (nextDataIndex >= data.Length)
            {
                throw new OverflowException("data array isn't long enough to accomodate new data");
                // in this situation the solution would be:
                //   1. clear the plot
                //   2. create a new larger array
                //   3. copy the old data into the start of the larger array
                //   4. plot the new (larger) array
                //   5. continue to update the new array
            }

            double randomValue = Math.Round(rand.NextDouble() - .5, 3);
            double latestValue = data[nextDataIndex - 1] + randomValue;
            data[nextDataIndex] = latestValue;
            ReadingsTextbox.Text = $"{nextDataIndex + 1}";
            LatestValueTextbox.Text = $"{latestValue:0.000}";
            nextDataIndex += 1;
        }

        void Render(object sender, EventArgs e)
        {
                wpfPlot1.plt.AxisAuto();
            wpfPlot1.Render(skipIfCurrentlyRendering: true);
        }

        private void DisableAutoAxis(object sender, RoutedEventArgs e)
        {
            wpfPlot1.plt.AxisAuto(verticalMargin: .5);
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions