Click here to Skip to main content
15,868,164 members
Articles / Desktop Programming / WPF
Article

WPF Real-time Monitor Control (Rolling Monitor)

Rate me:
Please Sign up or sign in to vote.
4.32/5 (9 votes)
25 Apr 2008CPOL3 min read 90.7K   5.9K   77   18
An article introducing the WPF Realtime Monitor Control, for creating a real-time view of continuous data

Code version 1.0.0.1

Image 1

^^^ Monitor Demo

monitor2.jpg

^^^ Rolling Monitor as used in CIRIP (A Computationally Intelligent Railway Intervention Planner) for monitoring connection count and thread count.

Introduction

This article presents the WPF Rolling Monitor aka Realtime Monitor Control. It is used to present real-time continuous data in a simple to use control with automatic updates. The monitor displays data in a similar manor to that of the Microsoft Windows Task Manager > Performance CPU Usage History view.

Using the Code

The monitor is built around two classes, RollingSeries and RollingMonitor. RollingMonitor is the control added to the interface, while RollingSeries represents a continous stream of data.

RollingSeries

The constructor accepts a reference to an instantiated RollingMonitor and a NextValueDelegate. The NextValueDelegate...

C#
public delegate double NextValueDelegate();

... returns the current value of continues trend of data (e.g. current CPU usage).

RollingSeries has the following accessor properties;

  • IsRunning - Pauses the thread reading from the NextValueDelegate. Note that pausing a RollingSeries does not automatically pause all other RollingSeries associated with a specific RollingMonitor.
  • LineBrush - The Brush used for rendering the data on the monitor.
  • LineThickness - The thickness of the rendered line on the monitor.

RollingMonitor

As previously stated, the RollingMonitor class is the UIElement added to the user interface which displays the data of the RollingSeries. It has a number of properties for customising the look and feel of the displayed output;

  • MaxValue - The maximum value the monitor is capable of displaying; any value greater than this will be rendered at the max value level (see demo example).
  • MinValue - The minimum value the monitor is capable of displaying; any value lower than this will be rendered at the min value level.
  • MaintainHistoryCount* - The number of previous history data to maintain; higher values result in higher computational complexity of rendering and greater memory usage, however too low a value and the whole monitor will not be filled.
  • UpdateInterval - The amount of time (in milliseconds) before the next data is retrieved; a higher value slows the speed of the monitor down and hence the MaintainHistoryCount may be lowered resulting in lower computational complexity. Lower values of UpdateInterval results in jerkier looking animation.
  • MinValueSpacing - Used to set the minimum with between UpdateInterval spacing so that data does not become mashed when the control is resized relatively narrow.

*Note in version 1.0.0.1 the parameter of RollingMonitor must be set prior to creating RollingSeries; this will be improved upon in later versions.

Example Code

Window1.xaml

<Window x:Class="WPFRollingMonitorDemonstration.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:rolling="clr-namespace:DNBSoft.WPF.RollingMonitor;assembly=WPFRollingMonitor"
    Title="Rolling Monitor Demonstration" Height="100" Width="300">
    <rolling:RollingMonitor Name="monitor" Margin="5"/>
</Window>

Window1.xaml.cs

C#
namespace WPFRollingMonitorDemonstration
{
    public partial class Window1 : Window
    {
        private Random random = new Random();

        public Window1()
        {
            InitializeComponent();

            RollingSeries s1 = new RollingSeries(monitor, new RollingSeries.NextValueDelegate(NextValue));
            RollingSeries s2 = new RollingSeries(monitor, new RollingSeries.NextValueDelegate(NextValue));
            s2.LineBrush = new SolidColorBrush(Color.FromRgb(255, 0, 0));
            s2.LineThickness = 0.25;
            RollingSeries s3 = new RollingSeries(monitor, new RollingSeries.NextValueDelegate(NextValue));
            s3.LineBrush = new SolidColorBrush(Color.FromRgb(0, 255, 0));
            s3.LineThickness = 0.25;

            monitor.MaxValue = 25;
        }

        private double NextValue()
        {
            return random.Next(0, 100);
        }
    }
}

Three instances of RollingSeries are created, all initialised with the same RollingMonitor and a delegate returning a random number between 0 and 100. Note however that the maximum value for the rolling monitor is set to 25, so any value above 25 appears as a value of 25 (see above).

Todo

  • Allow modification of RollingMonitor parameters after RollingSeries have been added.
  • Monitor data series customisation via user interface.
  • Performance optimisation.
  • Automatic scaling.
  • Axis labels.

History

Version 1.0.0.0 - Initial build

Additional Licensing Notes

Please feel free to use this in your work, however please be aware that a modified The Code Project Open License (CPOL) is in use; basically it is the same as the standard license except that this code must not be used for commercial or not-for-profit commercial use without prior authorisation. Please see license.txt or license.pdf in the included source and demo files.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Rail Research UK
United Kingdom United Kingdom
I originally studied for a masters in engineering of software engineering at The University of Birmingham during 2000-2004, of which I received a 2:1. I continued at Birmingham University working with Civil Engineering and Rail Research UK where I am currently in my final year of a 3 year PhD project developing a Computational Intelligent Approach to Railway Intervention Planning. Although my work has a significant focus on railway engineering and associated practices much of my work is with data mining (on SQL Server 2008) and computational intelligence (CI) techniques. My key areas of expertise in CI are clustering algorithms (including Rival Penalised Competitive Learning) and evolutionary algorithms.

Outside of my formal work I enjoy testing the latest technologies such as .NET 3.5 and the many frameworks of which it comprises (mainly WPF). I have several projects on the go including a .NET and DirectX port of Quake 3 and many utility libraries. I also maintain an extensive website coded in Cold Fusion which is regularly updated; more information is available about me there.

Comments and Discussions

 
QuestionRevised to Plot Sine Wave Pin
BarbPresley38-Mar-14 14:58
BarbPresley38-Mar-14 14:58 
QuestionSmoother scrolling Pin
TobiasVdb24-Jan-12 23:56
TobiasVdb24-Jan-12 23:56 
AnswerRe: Smoother scrolling Pin
Derek Bartram3-Apr-13 12:50
Derek Bartram3-Apr-13 12:50 
Questionhow to stop the thread Pin
mickwijaya25-Jul-11 17:22
mickwijaya25-Jul-11 17:22 
AnswerRe: how to stop the thread Pin
Nils de Jong29-Dec-11 22:29
Nils de Jong29-Dec-11 22:29 
GeneralRe: how to stop the thread Pin
79850015021-Jul-12 19:35
79850015021-Jul-12 19:35 
Generalcool Pin
zhujinlong1984091317-Apr-09 0:03
zhujinlong1984091317-Apr-09 0:03 
GeneralDisappointed with CPU performance Pin
Glynn4-Jan-09 23:35
Glynn4-Jan-09 23:35 
GeneralRe: Disappointed with CPU performance Pin
Derek Bartram5-Jan-09 23:54
Derek Bartram5-Jan-09 23:54 
GeneralRe: Disappointed with CPU performance Pin
andyb197929-Mar-12 3:19
andyb197929-Mar-12 3:19 
GeneralFeeding data from a seperate application or serial port Pin
PeterKovach11-Nov-08 6:06
PeterKovach11-Nov-08 6:06 
GeneralRe: Feeding data from a seperate application or serial port Pin
Derek Bartram11-Nov-08 6:39
Derek Bartram11-Nov-08 6:39 
GeneralRe: Feeding data from a seperate application or serial port Pin
PeterKovach11-Nov-08 6:49
PeterKovach11-Nov-08 6:49 
GeneralRe: Feeding data from a seperate application or serial port Pin
Derek Bartram11-Nov-08 7:02
Derek Bartram11-Nov-08 7:02 
GeneralRe: Feeding data from a seperate application or serial port Pin
PeterKovach11-Nov-08 7:30
PeterKovach11-Nov-08 7:30 
GeneralA good start Pin
Keith Rule25-Apr-08 12:35
professionalKeith Rule25-Apr-08 12:35 
GeneralRe: A good start Pin
Derek Bartram25-Apr-08 13:21
Derek Bartram25-Apr-08 13:21 
GeneralRe: A good start Pin
PeterKovach11-Nov-08 7:54
PeterKovach11-Nov-08 7:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.