Introduction
In VB, when it comes to visualizing data in the form of charts, developers seldom think beyond MSChart. The MSChart component may seem adequate, but the fact is - it has some serious limitations. Some of the most significant limitations of MSChart are that it is not interactive, doesn’t support animation and drill-down. So with MSChart, it is only possible to incorporate monotonous static charts in Visual Basic applications.
In this tutorial, you will be introduced to FusionCharts for VB – a charting component that helps you develop Flash-based animated and interactive charts for VB applications. No knowledge whatsoever of Flash is required to be able to use the component. The only requirement is for Adobe Flash Player 9 plugin to be installed. The plugin is widespread and can be downloaded from here.
Creating Charts for VB Applications
It is extremely easy to implement FusionCharts for VB. We will take a step-by-step approach to first see how to incorporate a chart in a VB application and then set up advanced features like drill-down and saving the chart as an image.
FusionCharts for VB can be downloaded from the FusionCharts Website. To install the component – just double click the setup.exe file and follow the instructions displayed on the dialog box.
So you are all set. Let's get started.
A simple example: Creating a pie chart
1. Create a Visual Basic project.

FusionCharts for VB supports multiple data input methods - from XML string (called dataXML method), XML file (called dataURL method), using individual data input, arrays and from databases too.
Since I said this will be a simple example, we will be taking a look at only the dataXML and Individual Data input method. And we will use the other methods in other examples later on in the tutorial.
5. Add the following three buttons to the Form:
Control |
Name |
Caption |
Command1 |
cmdIndividualData |
&Individual data |
Command2 |
cmdXMLString |
XML &String |
Command3 |
cmdExit |
E&xit |

6. Switch to the code view and enter the following code in the code window.
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdIndividualData_Click()
FusionCharts1.ChartType = pie3d
FusionCharts1.Data.setChartParams "caption=Match Score; xAxisName=Player Name;yAxisName=Score"
FusionCharts1.Data.addChartData "90", "label=David"
FusionCharts1.Data.addChartData "70", "label=Josh"
FusionCharts1.Data.addChartData "80", "label=Brain"
FusionCharts1.RenderChart
End Sub
Private Sub cmdXMLString_Click()
Dim XML As String
XML = "<chart caption='Match Score' xAxisName='Player Name' yAxisName='Score'><set value='90' label='David' /><set value='70' label='Josh' /><set value='85' label='Brain' /></chart>"
FusionCharts1.ChartType = pie3d
FusionCharts1.setDataXML = XML
End Sub
7. Press F5 to run the project - the following screen will be displayed. The screen doesn’t display a chart as data is yet to be loaded.

Wowed? Let's try out a different chart type now.
Creating a multi-series column chart using data arrays
1. Create a new project and add the FusionCharts control to the form (steps 1 - 4 of instructions for creating a single-series chart).
2. Add the following controls to the form:
Control |
Name |
Caption |
Command1 |
cmdArrayData |
&Using Array |
Command2 |
cmdExit |
E&xit |
3. Switch to the code view and enter the following code in the code window.
Private Sub cmdArrayData_Click()
' Array to store category names
Dim arrCatName(0 To 5) As String
' Array to store datasets and chart data
Dim arrDataArray(0 To 1, 0 To 7) As String
' Variable to store chart parameters
Dim chartParameters As String
' Assigning chart parameters
chartParameters = "ShowValues=0;caption=Business Results 2008 v 2007;xAxisName=Month;yAxisName=Revenue;numberPrefix=$"
' Assigning Category names
arrCatName(0) = "Jan"
arrCatName(1) = "Feb"
arrCatName(2) = "Mar"
arrCatName(3) = "Apr"
arrCatName(4) = "May"
arrCatName(5) = "Jun"
' Assigning First Dataset seriesnames
arrDataArray(0, 0) = "2008"
' Assigning Second Dataset seriesnames
arrDataArray(1, 0) = "2007"
' Assigning chart data to First Dataset
arrDataArray(0, 2) = "27400"
arrDataArray(0, 3) = "29800"
arrDataArray(0, 4) = "25800"
arrDataArray(0, 5) = "26800"
arrDataArray(0, 6) = "29600"
arrDataArray(0, 7) = "32600"
' Assigning chart data to Second Dataset
arrDataArray(1, 2) = "10000"
arrDataArray(1, 3) = "11500"
arrDataArray(1, 4) = "12500"
arrDataArray(1, 5) = "15000"
arrDataArray(1, 6) = "11000"
arrDataArray(1, 7) = "9800"
' Sets chart's parameters
Call FusionCharts1.Data.setChartParams(chartParameters)
' Passing array to the FusionCharts component
Call FusionCharts1.Data.addChartDataFromArray(arrDataArray, arrCatName)
' Sets Chart Type
FusionCharts1.ChartType = mscolumn3d
' Calling Chart Rendering Method
FusionCharts1.RenderChart
End Sub
Private Sub cmdExit_Click()
End
End Sub
4. Press F5 to run the code and then click the ‘Using Array’ button to render the chart.
Creating a combination chart using data drawn from a database
1. Create a new project and add the FusionCharts control to the form (steps 1 - 4 of instructions for creating a single-series chart).
2. Next, add the following controls to the form:
Control |
Name |
Caption |
Command1 |
cmdDatabase |
&Data from Database |
Command2 |
cmdExit |
E&xit |
Adodc1 |
Adodc1 |
|
3. Open the component window using CTRL + T or by selecting the ‘Component’ option from the ‘Project’ menu. Next, select ‘Microsoft ADO Data’, and then click ‘Apply’ and finally click the ‘OK’ button. Once the control is added to the form, drag it out of the visible area of the form – in order to make it invisible to the user.

4. Switch to the code view and enter the following code in the code window.
Private Sub cmdDatabase_Click()
' Configures ADODC control
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\FactoryDB.mdb" & ";Persist Security Info=False"
Adodc1.CommandType = adCmdTable
Adodc1.RecordSource = "MSCommon"
Adodc1.Refresh
' Variable to store chart parameters
Dim chartParameters As String
' Dataset parameters array
Dim arrDatasetParams(0 To 2) As String
arrDatasetParams(1) = "renderAs=Area;showValues=0"
arrDatasetParams(2) = "renderAs=Line;showValues=0"
chartParameters = "showValues=0;caption=Business Results 2007 v 2008;xAxisName=Month;yAxisName=Revenue;numberPrefix=$"
' Passing Chart's Parameters
Call FusionCharts1.Data.setChartParams(chartParameters)
' Changes Chart Type to Combination3D
FusionCharts1.ChartType = mscombi3d
' Sets ADODC recordset reference and database parameters
Call FusionCharts1.Data.addDatasetsFromDatabase(Adodc1.Recordset, "Months", "2008;2007;Quantity", arrDatasetParams)
' Calls render chart method
FusionCharts1.RenderChart
End Sub
Private Sub cmdExit_Click()
End
End Sub
5. Press F5 to run the code and then click the ‘Data from Database’ button – to render the chart.

Now that we have explored a number of chart types, we will look at how to improve the functionality of the chart.
Saving chart as image
For this example we’ll build upon the combination chart project itself.
1. Add the following controls to the form.
Control |
Name |
Caption |
Command1 |
cmdCaptureImage |
Capture &Image |
Command2 |
cmdSaveImage |
&Save Image |
Picture1 |
Picture1 |
|
2. Arrange the form as shown below.

3. Switch to the code view and enter the following code in the code window.
Private Sub cmdSaveImage_Click()
FusionCharts1.SaveAsImage (True)
End Sub
Private Sub cmdCaptureImage_Click()
Picture1.Picture = FusionCharts1.GetPicture
End Sub
4. Press F5 to run the application and then click the ‘Data from Database’ button to render the chart.
5. Click the ‘Capture Image’ button the image of the chart will now be displayed in the Picture Box.
6. Next, click the ‘Save’ button, and in the ‘Save As’ dialog box specify the location where you wish to save the image of the chart.

Creating a chart with drilldown functionality
1. Create a new project and add the FusionCharts control to the form (steps 1 - 4 of instructions for creating a single-series chart).
2. Add the following controls to the form.
Control |
Name |
Caption |
FusionCharts |
FusionCharts1 |
Capture &Image |
FusionCharts |
FusionCharts1 |
&Save Image |
CommandButton |
cmdExit |
E&xit |
3. Arrange the form in the following manner.

4. Switch to the code view and enter the following code in the code window.
Private Sub cmdExit_Click()
End
End Sub
Private Sub SetFirstChart()
FusionCharts1.ChartType = column3d
Dim sChartParameters As String
' Setting chart parameters.
sChartParameters = "caption=Half Yearly Sales Summary;subcaption=For the year 2008 - First Half;xAxisName=Month;yAxisName=Sales; numberPrefix=$"
' Adding data to the chart,
' And at set parameter we are using link attribute with "J-" parameter, which helps us
' to track the click event.
' We are passing single parameter.
Call FusionCharts1.Data.addChartData("500", "label=Factory 1;link=J-CallFunctionOne-SingleParameter")
' We are passing two parameters separated by comma (,).
Call FusionCharts1.Data.addChartData("400", "label=Factory 2;link=J-CallFunctionTwo-1st Parameter,2nd Parameter")
' Passing without any parameter.
Call FusionCharts1.Data.addChartData("350", "label=Factory 3;link=J-CallFunctionThree")
' Finally render the chart.
Call FusionCharts1.RenderChart
End Sub
Private Sub Form_Load()
' Generates chart data and renders chart.
Call SetFirstChart
End Sub
Private Sub FusionCharts1_DrillDown(ByVal ActionName As String, ByVal ActionParameter As Variant)
' At ActionName, we will get the value which is given just after J-
' At ActionParameter, we will get the value which is given just after J-ActionName-
' XML String variable
Dim XML As String
' Applying Select statement with ActionName
Select Case ActionName
' If ActionName is CallFunctionOne
Case "CallFunctionOne":
' Creates XML
XML = "<chart caption='Half Yearly Sales Summary' subcaption='Factory 1' xAxisName='Month' yAxisName='Sales' numberPrefix='$' >"
XML = XML & "<set label='Jan' value='17400' />"
XML = XML & "<set label='Feb' value='19800'/>"
XML = XML & "<set label='Mar' value='21800'/>"
XML = XML & "<set label='Apr' value='23000'/>"
XML = XML & "<set label='May' value='29000'/>"
XML = XML & "<set label='Jun' value='27600'/>"
XML = XML & "</chart>"
' If ActionName is CallFunctionTwo
Case "CallFunctionTwo":
' Creates XML
XML = "<chart caption='Half Yearly Sales Summary' subcaption='Factory 2' xAxisName='Month' yAxisName='Sales' numberPrefix='$' >"
XML = XML & "<set label='Jan' value='1400' />"
XML = XML & "<set label='Feb' value='1800' />"
XML = XML & "<set label='Mar' value='2800' />"
XML = XML & "<set label='Apr' value='2000' />"
XML = XML & "<set label='May' value='2000' />"
XML = XML & "<set label='Jun' value='2600' />"
XML = XML & "</chart>"
' If ActionName is CallFunctionThree
Case "CallFunctionThree":
' Creates XML
XML = "<chart caption='Half Yearly Sales Summary' subcaption='Factory 3' xAxisName='Month' yAxisName='Sales' numberPrefix='$' >"
XML = XML & "<set label='Jan' value='400' />"
XML = XML & "<set label='Feb' value='800' />"
XML = XML & "<set label='Mar' value='800' />"
XML = XML & "<set label='Apr' value='300' />"
XML = XML & "<set label='May' value='900' />"
XML = XML & "<set label='Jun' value='700' />"
XML = XML & "</chart>"
End Select
' Changing chart type to column2d
FusionCharts2.ChartType = column2d
' Providing XML to the chart.
FusionCharts2.setDataXML = XML
End Sub
The drill down functionality enables a click event on any of the column/bars of the chart to further enhance that data set and display another chart. For this we use a link attribute with J- parameter followed by function name (CallFunction(one/two/three)), and the necessary function parameters. Now when we drill down into any of the column/bars, it invokes FusionCharts1_DrillDown event. Here we specify the XML for each of the new charts.
5. Press F5 to run the project and then click ‘XML String’ button to render the chart.
6. Click on any of the columns of the chart – this causes another chart to be displayed in the ‘Detail Report’ window.
In these examples, you have seen how you can easily create exciting charts in VB. The examples demonstrated only few of the features of FusionCharts for VB. Some of the other highlights are:.
Technical reviewer for FusionCharts: Beginner’s Guide
If interested in reviewing "FusionCharts: Beginner’s Guide" for Packt Publishing, contact alkan@packtpub.com
Inquiry About OCX
I am very much interested in byuing this great ocx however I like to know if there is a way to embed the Ocx inside my program where it will be built in and no need for distriputig it and installination
Appreciate your feed back
Thanks
send me vb 6 project on my id
hello
send me plz project on vb on my id:vasavadakirtan@gmail.com
microsoft.jet oledb 3.51 connection
can i connect using the service provider microsoft jet oledb 3.51
I am failed to fetch the chart
please help me..
How can we create help file in vb6.0
Sir, Please help for creating help file in vb6.0
Creating a combination chart using data drawn from a database
where is the database? what should the database named FactoryDB.mdb contains?
Post new comment