Drawing Graphs and Charts with VB.NET - A Demo using the .NET component csASPNetGraph

To run this demo you need the csASPNetGraph trial component as well as MS Visual Studio.NET. The trial component and the example files are available below:

Download the trial csASPNetGraph control - csngt.zip (588 KB)

Download the demo VB.NET project - VBNETGraphDemo.zip (12 KB)

The sample files contain a text file, "readme.txt" which describes the demo and how to make it run. Some important points should be noted.

First, the csASPNetGraph component is not included as part of the demo and it must be downloaded separately using the link above. It needs to be imported into the Visual Studio tool box and then dropped onto the project form. The project code assumes that the default name of GraphClass1 will be used for the component class. The project will not compile without the component.

The component is non visual and so a PictureBox is used to display the graph image. This is achieved using the following code:

PictureBox1.Image = GraphClass1.GraphToBitmap

csASPNetGraph is designed for use in ASP.NET and for displaying in web pages and for that reason colours are specified as 6 character strings, to match the behaviour of HTML. For example:

If CheckBox3.CheckState Then
  GraphClass1.PlotAreaColor = "EEEEEE"
Else
  GraphClass1.PlotAreaColor = "FFFFFF"
End If

This sets the PlotAreaColor property to either a light grey or white depending on a check box state.

The individual font properties cannot be set directly in .NET because they are read only. When a font needs changing from its default settings all the properties must be specified using the New command, for example:

GraphClass1.TitleFont = New Font("Arial", 10, FontStyle.Bold)

For full details of the methods and properties, refer to the instructions provided in the zip file with the component DLL.