Article Options
Premium Sponsor
Premium Sponsor

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

 

Sponsored Links