Our chosen language for development is C#. You can use any basic IDE – we have made use of Microsoft Visual C# 2008 Express Edition. Make sure you have Adobe Flash Player 8 or higher installed. If you don’t, you can download the same from here.
1. Create a new Windows Forms Application Project. In the Design View, right click on the Toolbox and click on Choose Items.
2. In the Choose Toolbox Items dialog box, under the COM Components tab, select Shockwave Flash Object. If this object is not being displayed, then please check whether Flash Player is installed on your system.
3. Right at the bottom in your Toolbox, an object titled Shockwave Flash Object will be included. Select and drag it on to your form. In the Properties Window, change its name to ChartContainer. If the name already didn’t suggest so, this is where the chart will be displayed.
4. Finally add a button to your form. Change its name to btnLoadChart and its text to Load Chart from the Properties Window. That will complete the design aspect of things. The final form would look as under:
5. Now that we are done with design, lets get down to coding. The button btnLoadChart when clicked will load the chart. So in the btnLoadChart_Click event, add the following code:
//Specify the format, path and name of the swf file which will render the chart.
//if "file:///" is added before the path and the XML after the path in the format
//then the chart will be loaded directly with no possibilities of any error. For a different chart, change the
//name from column2d to the required chart, add the chart swf to the application startuppath and modify the XML as required.
string appPath = "file:///" + Application.StartupPath + "Column2D.swf";
//replace all "" in the path with "/"
appPath = appPath.Replace("", "/");
//Creating the string which will act as the XML according to the format
string ChartXML = appPath + @"?dataXML= ®isterwithjs=1";
//Passing the above string into the required parameter of the flash movie.
ChartContainer.Movie = ChartXML;
The chart XML can be modified according to your needs. If you run the application now and click on the Load Chart button, the chart will be generated.
Simple, isn’t it? The possibilities it opens for you are endless. Once you embed a chart in your form, you can design interactive charts using either user entered data or a remote data file. You can also export the charts as images or its data as a CSV file. We will see how to do all in our next post. So try this out in the meantime, and don’t forget to come back for the next part! Now you can also use jQuery charts for creating interactive charts and graphs.