Click here to Skip to main content
Click here to Skip to main content
Go to top

WPF Real-time Monitor Control (Rolling Monitor)

, 25 Apr 2008
Rate this:
Please Sign up or sign in to vote.
An article introducing the WPF Realtime Monitor Control, for creating a real-time view of continuous data

Code version 1.0.0.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...

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

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)

Share

About the Author

Derek Bartram
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

 
GeneralFeeding data from a seperate application or serial port PinmemberPeterKovach11-Nov-08 6:06 
GeneralRe: Feeding data from a seperate application or serial port PinmemberDerek Bartram11-Nov-08 6:39 
GeneralRe: Feeding data from a seperate application or serial port PinmemberPeterKovach11-Nov-08 6:49 
GeneralRe: Feeding data from a seperate application or serial port PinmemberDerek Bartram11-Nov-08 7:02 
GeneralRe: Feeding data from a seperate application or serial port PinmemberPeterKovach11-Nov-08 7:30 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 25 Apr 2008
Article Copyright 2008 by Derek Bartram
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid