Drawing Graphs and Charts with VB.NET - A Demo using ActiveX control csXGraph

Our csXGraph ActiveX control can be used in .NET applications and this page contains a downloadable demo. To run this demo you need the csXGraph trial ocx control installed on your system as well as MS Visual Studio.NET. The trial control and the example files are available below:

Download the trial csXGraph control - csXGraphTrial.exe (981 KB)

The demo VB.NET project - VBNETGraph.zip (110 KB)

Install csXGraphTrial, then extract the VB.NET demo files from the zip file, keeping the same directory structure. Start VB.NET, and open the project in solution file "VBNetGraph\VBNetGraph.sln".

This example is similar to the VB6 example supplied with the trial version and it shows the appropriate syntax to display a bar chart, a pie chart and a line graph. It also shows how to substitute labels on the x-axis of a line graph to show strings instead of numerical values.

The data types used by COM are not exactly the same as those used by .NET and with csXGraph these differences affect the use of colours and fonts. The methods that use OLE_COLOR as a parameter, such as AddData and AddPoint, will use a UInt32 instead, for example:

AxDraw1.AddData("Item 1", 14, System.UInt32.Parse(&HFF))

This converts the hexadecimal value FF into a UInt32 value to give the colour red.

Properties representing colours use the data type System.Drawing.Color, for example:

If CheckBox3.CheckState Then
  AxDraw1.PlotAreaColor = System.Drawing.Color.FromArgb(&HEEEEEE)
Else
  AxDraw1.PlotAreaColor = System.Drawing.Color.White
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:

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

Cookies

This site uses cookies for functionality, traffic analysis and for targeted advertising. Click the Accept button to accept our Cookie Policy. The Cookie Policy page offers configuration for a reduced set of cookies for this site.