Rendering FusionCharts in VB.NET and Windows-based Form Applications

FusionCharts Suite XT is an easy-to-use JavaScript charting library that can be integrated with most major frameworks, programming languages, and applications. VB.NET is one such widely used object-oriented programming language that is implemented using the .NET framework.
This tutorial talks about integrating FusionCharts Suite XT with VB.NET and Windows-based form applications.

For rendering charts created using FusionCharts in VB.NET and Windows-based applications, we can use one from the following three methods:

  • Rendering charts by generating the HTML code as a string and passing it to the WebBrowser control
  • Rendering charts by navigating to a local HTML file that contains the chart object
  • Rendering charts by including the FusionCharts ASP.NET server-side wrapper in the project

Requirements

We need the following applications installed before rendering FusionCharts in VB.NET and Windows-based applications:

Method 1: Rendering Charts by Passing the HTML String to the WebBrowser Control

Steps

  1. Open Visual Studio. From the File menu, select New > Project .
    The New Project dialog box opens.
  2. From Installed > Templates , select Windows Forms Application , as shown in the image below:
    A form, with the default name Form1.vb , opens.
  3. Press F4 to open the Properties window.
    Set the Text property to Rendering FusionCharts , as shown in the image below:
    The Text property is used to set the form heading.
  4. Open the Toolbox .
  5. From the Toolbox , drag the WebBrowser control and drop it on the form.
  6. Add a new folder in the project hierarchy and name it Scripts.
    Copy the fusioncharts.js and fusioncharts.charts.js files and paste them in the Scripts folder.
  7. Open Form1.vb and place the following code within the Load event handler. The code given below is the complete HTML source that will be stored in the StringBuilder variable and will be passed as the source to the WebBrowser control.
  8. Run the application. Your output should look as shown in the image below:

Method 2: Rendering Charts by Navigating to a Local HTML file

Steps

  1. Create an HTML file in the root folder of the project and name it HTMLPage1.html.
  2. Copy the following code in the HTMLPage1.html file:
  3. Add the code given below in the Load event handler of the form:
  4. Run the application. Your output should look as shown in the image below:

Method 3: Rendering Charts using the FusionCharts ASP.NET Wrapper

Steps

  1. Add a reference of the fusioncharts.dll file to the project to include the FusionCharts ASP.NET wrapper.
  2. Copy the code given below in the Load event handler of the form:
  3. Run the application. Your output should look as shown in the image below:

If you find any difficulty in rendering the chart or you see any error in your code, click here to download the complete source code of the sample project we have created for this tutorial.

Was There a Problem Rendering the Charts?

In case something went wrong and you are unable to see the chart, check for the following:

  • The chart ID should be unique for all charts rendered on the same page. Otherwise, it will result in a JavaScript error.
  • If the chart does not show up at all, check if the fusioncharts.js and FusionCharts wrapper FusionCharts.java was loaded. Also, check if the path to the fusioncharts.js and the FusionCharts.java files is correct, and whether the files exist in that location.

Leave a Comment