Bandwidth monitor with graph vb.net development
BANDWIDTH MONITOR WITH GRAPH USING CHART CONTROL
Filename : Bandwidth Monitor with Chart.zip
Project File available and is attached
Working version using MSCharts
REQUIREMENT:
Microsoft Chart Controls for Microsoft .NET Framework 3.5
Product Page
Direct Link
after working on the system.drawing version, i've applied the same concept here and found out everything is easier to implement, and aesthetically looks better.
This is not copied from the internet, it's my own genuine work.
Declaration
Code:
Dim downloadvalueplot As New ArrayList
Dim uploadvalueplot As New ArrayList
Dim counter As Integer = 0
Working Code
Code:
counter = counter + 1
'--------------------------------------------------------------------------------------------------------------------
'GRAPHING CODES
'uses a chart, easier to implement compared to a system drawing approach
'--------------------------------------------------------------------------------------------------------------------
'inserts current download/upload rate on the first index of the array
'i choose first since it would be easier for plotting porpuses and to remove unused array contents
downloadvalueplot.Insert(0, (DLoad - LastDLoad) / 1024)
uploadvalueplot.Insert(0, (ULoad - LastULoad) / 1024)
'SUSPENDS UPDATES
'this removes the flicker effect and makes sures that all plotting is finished at the background
'before displaying them
ChartGraph.Series(0).Points.SuspendUpdates()
ChartGraph.Series(1).Points.SuspendUpdates()
'this part clears the (previous)points
'this also remove the unwanted connecting line from the first value on a line graph
ChartGraph.Series(0).Points.Clear()
ChartGraph.Series(1).Points.Clear()
'ADD VALUES (POINTS) TO THE SERIES
'the number of x corresponds to the chart width
Dim ichartmax As Integer = ChartGraph.Width / 12
For ichart As Integer = 0 To ichartmax
ChartGraph.Series(0).Points.InsertXY(ichart, ichart + 1, downloadvalueplot(ichart))
ChartGraph.Series(1).Points.InsertXY(ichart, ichart + 1, uploadvalueplot(ichart))
If ichart = counter - 1 Then
Exit For
ElseIf ichart = ichartmax Then
'removes array contents that will no longer be used
downloadvalueplot.RemoveRange(ichartmax + 1, downloadvalueplot.Count - 1)
uploadvalueplot.RemoveRange(ichartmax + 1, uploadvalueplot.Count - 1)
End If
Next
'RESUME UPDATES
'proceeds to update the chart display
ChartGraph.Series(0).Points.ResumeUpdates()
ChartGraph.Series(1).Points.ResumeUpdates()
NOTE:
still need to work out on how to implement a predetermined amount off x values regardless of array contents.
code posted is designed to work on my previously posted bandwidth monitor, you may have to change stuff to suit to your projects
requires a chart named "ChartGraph" configured at least with 2 series
BANDWIDTH MONITOR WITH GRAPH USING SYSTEM.DRAWING
Filename : Bandwidth Monitor with Graph.zip
Project File available and is attached
working prototype on a very crude approach on a bandwidth monitor graph using system.drawing - no chart needed.
this is from the internet - code is not mine.
will integrate this soon on my future release - had to beautify it first
and make it more dynamic and remove the scroll bar
NOTE:
there is a problem with the graph when the max values change the graph does not change the past visual representation accordingly. if this bothers you then just set
Code:
PictureBoxValues.Image = DisplayVerticalValues(PictureBoxValues, 10, 0, (dmax / 1024) + 10)
PictureBoxGraph.Image = DisplayGuidelinesAndChart(PictureBoxGraph, 10, 3, (DLoad - LastDLoad) / 1024, 0, (dmax / 1024) + 10)
PictureBoxValuesUpload.Image = DisplayVerticalValues(PictureBoxValuesUpload, 10, 0, (umax / 1024) + 10)
PictureBoxGraphUpload.Image = DisplayUploadGuidelinesAndChart(PictureBoxGraphUpload, 10, 3, (ULoad - LastULoad) / 1024, 0, (umax / 1024) + 10)
TO
Code:
PictureBoxValues.Image = DisplayVerticalValues(PictureBoxValues, 10, 0, [COLOR="red"]3686[/COLOR])
PictureBoxGraph.Image = DisplayGuidelinesAndChart(PictureBoxGraph, 10, 3, (DLoad - LastDLoad) / 1024, 0, [COLOR="red"]3686[/COLOR])
PictureBoxValuesUpload.Image = DisplayVerticalValues(PictureBoxValuesUpload, 10, 0, [COLOR="Red"]512[/COLOR])
PictureBoxGraphUpload.Image = DisplayUploadGuidelinesAndChart(PictureBoxGraphUpload, 10, 3, (ULoad - LastULoad) / 1024, 0, [COLOR="red"]512[/COLOR])
wherein those in red represent you target maximum bandwidth
still under development.
INSTRUCTIONS:
to integrate to your own project the easy way:
1. disable the timers (timerbandwidth and timerlatency)
2. copy all controls (do not include the form) and paste them to your project
3. copy codes to your project
4. enable timerbandwidth and timerlatency and the code will do the rest