DevCity.NET - http://devcity.net
Review of VBChart
http://devcity.net/Articles/191/1/article.aspx
Ben Spencer
For the last 30 years I have developed Accounting software for the Oil & Gas industry (Exploration & Production, First Purchaser of Oil and Cash Market Oil Trading). Over the years, I have moved the applications to various platforms reaching the Windows platform in 2002. I limit my development on the Windows platform to Windows Forms applications using .Net. My education includes a B.S. degree in Electrical Engineering and a M.S. degree in Computer Science.  
by Ben Spencer
Published on 1/18/2006
 

Introduction

   In my many years of software development, one comment I have often heard from my clients’ upper management is “I don’t want to see details.  Show me a picture”.  A well designed chart or graph can provide management with a clearer picture of the company’s status than any number of reports.   The VBChart Graphing Tool For .NET  can provide that picture from existing data with surprising ease.  

 

   During the review process I was able to produce a number of aesthetically pleasing charts and graphs with minimal coding.  It’s hard to imagine a product that would be easier to use. For this review, I used a Windows Forms application in VB.NET.  Additionally, the product supports ASP.NET for Web applications


Download and Installation

    The download and installation procedure is typical of any software.  Using the download  page, it’s a simple matter of entering some personal information (name, e-mail address, etc) along with a serial number, and selecting download via FTP or HTTP.  I chose the FTP option, and downloaded the installation package in a few minutes.  During the installation process, the product’s Help files are merged into the MSDN documentation.   They are subsequently available via the IDE’s Help index.  Sample code and walkthroughs are provided, as well as extensive documentation of the classes and methods.   The ReadMe file gives complete instructions on how to add the charting components to the IDE’s toolbox.  An evaluation edition is available from the VBChart download page and I encourage you to give it a try.

 

Bar Chart Example

Using my typical approach, I attempted to develop a chart without reading any of the extensive documentation provided by VBChart.  I dropped a VBWinChart on my form and the Chart Wizard appeared. 

 

 

 

   I selected a Bar2D type chart, entered a Chart Name, Left Axis title, and Bottom Axis title.  On the Data dialog screen, I entered an OLEDB connection string for an Oracle database.   Next, I entered a Select statement,  the column name for the Y-Axis and the column name for the X-Axis label.    I had my first chart without writing a single line of code:

 

 

  

    The key to producing any chart using VBChart is the creation or existence of an appropriate Dataset.  Each DataTable in a dataset’s table collection represents a series on the chart.  Each row in a DataTable represents a point on the x-axis and the value of a column in the row represents the y-axis.  The dataset can be created by using the Data dialog within the chart wizard, or the dataset can be created using an application’s data tier and bound to the chart in code.  The following code was used to bind a dataset contain 3 tables (series) to the bar chart:

 

‘Remove any existing series<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Me.VbChartWin1.Chart.RemoveAllSeries()

‘create a data provider for each series

Dim dataProv1 As DataSetDataProvider = New DataSetDataProvider(Me.ds, "Table1")

Dim dataProv2 As DataSetDataProvider = New DataSetDataProvider(Me.ds, "Table2")

Dim dataProv3 As DataSetDataProvider = New DataSetDataProvider(Me.ds, "Table3")

‘create the series

Dim p1Series As Series = New Series

Dim p2Series As Series = New Series

Dim p3Series As Series = New Series

‘Name each series

p1Series.SeriesName = "McClintock A"

p2Series.SeriesName = "Knight A-10"

p3Series.SeriesName = "Shepard #1"

‘bind each series to a data provider

p1Series.BindComponent(SeriesComponent.Y, dataProv1, "TS_TBBLS")

p2Series.BindComponent(SeriesComponent.Y, dataProv2, "TS_TBBLS")

p3Series.BindComponent(SeriesComponent.Y, dataProv3, "TS_TBBLS")

‘Add the series to the chart

Me.VbChartWin1.Chart.AddSeries(p1Series)

Me.VbChartWin1.Chart.AddSeries(p2Series)

Me.VbChartWin1.Chart.AddSeries(p3Series)

‘Set the x-axis label

p1Series.BindComponent(SeriesComponent.Label, dataProv, "TS_Month")

Me.VbChartWin1.Chart.Grid.AxisX.LabelSeries = p1Series

‘Create the chart

Me.VbChartWin1.Chart.RecalcLayout()

 

  

Producing this chart:

 

 

 

   The developer has complete control of the appearance of each chart.   The wide range of choices includes the background, fonts, series colors,  legends, titles, annotations and even  ToolTip type boxes can be displayed. 

 

 

Sample Code and Gallery

The following form contains four samples of the 40+ available charts.  VBChart’s  sample code web page offers a number of  samples  using the various charts and some of the features of each.  The gallery web page shows a more compete list of the available chart types.

 

 

  

 

 

Pie Chart Example

As with all chart types, the pie chart is also driven by the dataset.  For the pie chart, each row in the DataTable represents a slice of the pie, with the value of the specified column in the row determining the slice size.  The code required to generate the pie chart is similar to the bar chart, but with only one series being used.

 

   The code snippet below is all that is needed to produce the pie chart displayed at the bottom left of the screenshot which follows it:

 

Me.VbChartWin1.Chart.RemoveAllSeries()

Dim dataProv As DataSetDataProvider = New DataSetDataProvider(Me.ds, "Table1")

Dim p1Series As Series = New Series 

p1Series.BindComponent(SeriesComponent.Y, dataProv, "TS_TBBLS")

‘set legend labels

For ix = 0 To ds.Tables("Table1").Rows.Count - 1

     Me.VbChartWin1.Chart.Grid.AxisPie.SetUserLabel(ix,

         ds.Tables("Table1").Rows(ix).Item("TS_Name"))

Next

‘explode slice 2

Me.VbChartWin1.Chart.GetSeriesDrawing(0).SetDataPointExplode(2, 15)

‘label each slice with a %

Me.VbChartWin1.Chart.GetSeriesDrawing(0).MarkerLabelsOn = True

Me.VbChartWin1.Chart.RecalcLayout()

 

    As you can see, very little developer effort is required to produce this clear and useful chart.

 

 

Conclusion

   The VBChart product is easy to use, has predefined chart types suitable to present almost any data in an aesthetically pleasing picture.   It gives the developer control of almost every aspect of the appearance and it is reasonably priced.  With the sample code provided on the web site, the learning curve for VBChart is relatively easy to navigate.  

 

     I would recommend this product to anyone requiring a charting tool for VB.NET and/or ASP.NET.