Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  Reviews  »  Software Reviews  »  Review of VBChart  »  Bar Chart Example
Review of VBChart
by Ben Spencer | Published  01/18/2006 | Software Reviews | Rating:
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. 

 

Sponsored Links