0

Issue


I have used a third party plugin called 'OxyPlot' for my WPF application. This plugin lets you plot points on different types of graphs.

On my graph I am displaying 'Bandwidth' of my computer for every second of when I click a certain button. The graph is updating correctly and working but I am unsure of how the graph automatically scrolls passed the 'Maximum' value I have set.

Code


This is the play button and will start the timer:

private void CameraPlayShow(object sender, RoutedEventArgs e)
{
    videoStreamTimer.Tick += new EventHandler(videoStreamTick);
    videoStreamTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
    videoStreamTimer.Start();
}

This is the method the timer calls, in here we call 'UpdateGraph':

private void videoStreamTick(object sender, EventArgs e)
{
    UpdateGraphStats();
}

This is the method where we add the new points:

private void UpdateGraphStats()
{
    _xValue++;

    try
    {
        DataTable serverStats = Global.podiaClient.GetLiveStats(Global.podiaSession, Global.gChapter.Guid).Tables[0];

         _bandwidth.Points.Add(new DataPoint(_xValue, GetEncoderCPU()));
         Model.InvalidatePlot(true);

    }
    catch (Exception ex)
    {          
    }
}

Finally, this is where I configure the PlotModel:

private static PlotModel CreateNormalDistributionModel()
{
    var plot = new PlotModel
    {
        Title = "Encoder CPU",
        Subtitle = "Lorem Ipsum Lorem Ipsum Lorem Ipsum"
    };

    plot.Axes.Add(new LinearAxis
    {
        Position = AxisPosition.Left,  
        TickStyle = TickStyle.Inside          

    });
    plot.Axes.Add(new LinearAxis
    {
        Position = AxisPosition.Bottom,
        IsPanEnabled = false,
        Minimum = 0,
        Maximum = 100,
        MinorStep = 1,
        MajorStep = 5,
        MajorTickSize = 2,
        MinorTickSize  = 1,
        TickStyle = TickStyle.Inside

    });

    return plot;
}

Summary


So as you can see from the code if the _xValue goes above 100 which is the maximum for the bottom axis. The graph will stop moving and i want it to scroll with the data.

Question


How can I get the graph to move to the right with the points I am plotting?

Ben Clarke
  • 1,051
  • 4
  • 21
  • 47

0 Answers0