|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis project is inspired by "Simple Performance Chart" by eclipse2k1. There are a few reasons for this project and article. The original article provides support for only one time serie and I required a few. Secondly, I found a number of limitations in the original control which I decided to fix and improve. The original article is well-written and covers the basics quite well, so I won't go into much detail, but run over the improvements and enhancements introduced. ImprovementsThe list of improvements is as follows:
Time Series CollectionFirst of all, I introduced time series. Each serie has a
Once the time serie object was all done, I created a collection of the series. However, due to a number of limitations (one of which is the absence of events) I could not use standard
/// <summary>
/// Event-enabled collection of <see cref="Serie"/>s.
/// </summary>
public class SerieCollection : ListWithEvents<Serie>
{
/// <summary>
/// Overrides <see cref="OnItemAdded"/>.
/// </summary>
/// <param name="e"></param>
protected override void OnItemAdded(ListItemEventArgs e)
{
base.OnItemAdded(e);
this[e.ItemIndex].ValueAdded += new EventHandler(
serieCollection_ValueAddedModified);
this[e.ItemIndex].ValueModified += new EventHandler(
serieCollection_ValueAddedModified);
}
private void serieCollection_ValueAddedModified(object sender,
EventArgs e)
{
Serie serie = sender as Serie;
if (serie == null)
return;
int index = this.IndexOf(serie);
if (index < 0)
return;
this.OnItemModified(new ListItemEventArgs(index));
}
}
I have also needed to override the Using the CodeDesign TimeUsing the control should be straightforward: reference the library (or drop it on your toolbox) and then add the control to your form. All of the properties exposed through the property grid should be sufficient to set the control. The time series management is made easy with the help of the "Collection Editor UI:"
ProgrammaticallyIt is also easy to manipulate the control programmatically. To add a new serie: // create a new time serie
Serie serie1 = new Serie();
// set the serie color
serie1.SerieStyle.SerieLine.Color = System.Drawing.Color.RoyalBlue;
// display an average value along with the average value line
// drawn as blue dash-dotted line
serie1.SerieStyle.DrawAverageLine = true;
serie1.SerieStyle.DrawAverageValue = true;
serie1.SerieStyle.AverageLine.Color = System.Drawing.Color.RoyalBlue;
serie1.SerieStyle.AverageLine.DashStyle =
System.Drawing.Drawing2D.DashStyle.DashDot;
// set the value formatting
serie1.SerieStyle.FormatAverageValue = "N2";
serie1.SerieStyle.FormatMaxMinValues = "N0";
this.performanceChart1.Series.Add(serie1);
Now add a new value to the serie: this.performanceChart1.Series[0].AddValue((decimal)this.random.Next(100));
Should you use the control in a synchronised manner and have this.performanceChart1.AddValueToQueue(/* serie index */0,
(decimal)this.random.Next(100));
ToolStripPerformanceChart ControlI thought it may be useful to have a small version of the performance chart just to provide the user with some feedback on running processes. The
It was surprisingly easy to create this control. All I had to do was to inherit from public partial class ToolStripPerformanceChart : ToolStripControlHost
{
protected override Padding DefaultMargin
{
get
{
if ((base.Owner != null) && (base.Owner is StatusStrip))
{
return new Padding(1, 3, 1, 3);
}
return new Padding(1, 2, 1, 1);
}
}
protected override Size DefaultSize
{
get
{
return new Size(16, 16);
}
}
public override Size GetPreferredSize(Size constrainingSize)
{
Size preferredSize = base.GetPreferredSize(constrainingSize);
if (preferredSize.Width < this.DefaultSize.Width)
preferredSize.Width = this.DefaultSize.Width;
if (preferredSize.Height < this.DefaultSize.Height)
preferredSize.Height = this.DefaultSize.Height;
return preferredSize;
}
}
Using this control is just as easy as using the this.toolStripPerformanceChart1.PerformanceChart.Series.Add(serie1);
History
Credits"Thank you" goes to eclipse2k1 for the original work.
|
||||||||||||||||||||||