![[Image: capture-1.gif]](https://dl.dropbox.com/u/23639317/Lol/troll/capture-1.gif)
Please note it only updates when you update a position! so if your not updating points it wont draw a new line
Code
//***Credits***
//Name: Jordan
//Alias: Coding4Noobs
//Website: www.emissarysolutions.org
//Application: eGraph
//Description: A simple graph control
//Version: 1.0
//***End Of Credits***
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Drawing.Design;
namespace E_Graph
{
class EGraph : Control
{
public int[] Points = { 0, 0, 0, 0 };
public int[] Points2 = { 0, 0, 0, 0 };
public Color bgColor = Color.FromArgb(55, 55, 55);
public int Spacing = 20;
public bool EnableStatistics = false;
private int Highest = 0;
private int Total = 0;
private int Total2 = 0;
private int Highest2 = 0;
private PictureBox Pic;
public EGraph()
{
Pic = new PictureBox();
this.Controls.Add(Pic);
Pic.Dock = DockStyle.Fill;
Pic.SizeMode = PictureBoxSizeMode.StretchImage;
//nothing yet
// DrawGraph();
}
/// <summary>
/// Updates the next point on your graph
/// </summary>
/// <param name="newPoint">The new point</param>
public void UpdatePoint(int newPoint, int newpoint2)
{
try
{
Points[0] = Points[1];
Points[1] = Points[2];
Points[2] = Points[3];
Points[3] = newPoint;
Points2[0] = Points2[1];
Points2[1] = Points2[2];
Points2[2] = Points2[3];
Points2[3] = newpoint2;
//if (newPoint > Highest)
//{
// Highest = newPoint;
//}
//if (newpoint2 > Highest2)
//{
// Highest2 = newpoint2;
//}
Highest = newPoint;
Highest2 = newpoint2;
Total2 += newpoint2;
Total += newPoint;
DrawGraph();
}
catch { }
}
//Draws the graph on the control
public void DrawGraph()
{
new System.Threading.Thread(() =>
{
try
{
Spacing = this.Width / 3;
Bitmap bmp = new Bitmap(this.Size.Width, this.Size.Height);
Graphics g = this.CreateGraphics();
g = Graphics.FromImage(bmp);
g.Clear(bgColor);
for (int i = 0; i < this.Width; i += 10)
{
g.DrawLine(Pens.DimGray, new Point(i, 0), new Point(i, this.Height));
}
for (int e = 0; e < this.Height; e += 10)
{
g.DrawLine(Pens.DimGray, new Point(0, e), new Point(this.Width, e));
}
if (EnableStatistics)
{
g.DrawString("Income /sec: " + Highest, new Font(DefaultFont.FontFamily, 8, FontStyle.Regular), Brushes.Red, new Point(4, this.Height - 16));
g.DrawString("Total Incomming: " + this.Total, new Font(DefaultFont.FontFamily, 8, FontStyle.Regular), Brushes.Red, new Point(4, this.Height - 32));
g.DrawString("Outgoing /sec: " + this.Highest2, new Font(DefaultFont.FontFamily, 8, FontStyle.Regular), Brushes.Blue, new Point(4, this.Height - 48));
g.DrawString("Total Out: " + this.Total2, new Font(DefaultFont.FontFamily, 8, FontStyle.Regular), Brushes.Blue, new Point(4, this.Height - 64));
}
g.DrawLine(Pens.Red, new Point(0, this.Height - Points[0]), new Point(Spacing, this.Height - Points[1]));
g.DrawLine(Pens.Red, new Point(Spacing, this.Height - Points[1]), new Point(Spacing * 2, this.Height - Points[2]));
g.DrawLine(Pens.Red, new Point(Spacing * 2, this.Height - Points[2]), new Point(Spacing * 3, this.Height - Points[3]));
Points[0] = Points[1];
Points[1] = Points[2];
Points[2] = Points[3];
g.DrawLine(Pens.Blue, new Point(0, this.Height - Points2[0]), new Point(Spacing, this.Height - Points2[1]));
g.DrawLine(Pens.Blue, new Point(Spacing, this.Height - Points2[1]), new Point(Spacing * 2, this.Height - Points2[2]));
g.DrawLine(Pens.Blue, new Point(Spacing * 2, this.Height - Points2[2]), new Point(Spacing * 3, this.Height - Points2[3]));
Points2[0] = Points2[1];
Points2[1] = Points2[2];
Points2[2] = Points2[3];
g.Dispose();
Pic.Image = bmp;
}
catch { }
}).Start();
}
}
}Usage:
Enable Statistic:
Code
eGraph1.EnableStatistics = true;
eGraph1.DrawGraph();Draw new Point:
Code
eGraph1.UpdatePoint(point1, point2);