Welcome!

PowerBuilder Authors: Chris Pollach, Yeshim Deniz, Jayaram Krishnaswamy, Kevin Benedict, Avi Rosenthal

Related Topics: PowerBuilder

PowerBuilder: Article

PowerBuilder with FusionCharts

Generating next-generation charts in WebForm applications

Back in August of 2007, I wrote an article entitled "Dynamically Generating Next-Generation Charts from PowerBuilder DataWindows" that demonstrated one method of dynamically generating Flash charts from within a PowerBuilder application. I was primarily writing that from the perspective of writing standard client/server applications. PowerBuilder 11 was just freshly released, and so while the option of creating WebForm applications that incorporated the technology was a factor that was being considered, it wasn't part of the sample at that time.

Fortunately, Haibo Ni of Sybase decided to take that on and came up with an implementation for PowerBuilder .NET WebForm applications. However, Haibo didn't just take my earlier example and create a WebForm target from it. He created his own similar solution based on a different library. I used XML/SWF Charts, a library that I just stumbled across while researching the possibility of generating Flash from PowerBuilder. Haibo used the free version of FusionCharts. FusionCharts is a commercial library, but they make the previous version available for free in order to encourage people to try out their product (and hopefully upgrade to the commercial version). The FusionCharts example as well as my previous XML/SWF Charts example are both available on Sybase's CodeXchange site.

It's hard to do the results justice with simple screenshots because (see Figure 1), as with the XML/SWF Charts sample I did, many of the FusionCharts involve animation. Also similar to the XML/SWF Charts sample, the underlying implementation involves providing an XML file to a Flash library in order to dynamically generate the chart.

But that's also where the similarity ends. With the XML/SWF Chart sample, there was only one Flash library used regardless of the chart type that would eventually be produced. Doing so required a great deal of the chart formatting information to be passed in with the data. That is, the XML file used for XML/SWF contained both formatting and data. Also, if you remember, the data had to be incorporated in the file in a method that was a bit non-native to XML.

With FusionCharts, there is a separate Flash library for each different chart type that is being generated. In addition, formatting information is passed into the library through parameters passed in via the HTML that the Flash library is embedded in (see Listing 1) or via attributes in the first line of the data XML (see Listing 2). As a result, the XML file that is provided contains primarily the data, and in a more normal data format for XML files (see Listing 2). It's also possible to pass the data directly into the library through a dataXML parameter as well, although for all of the examples the data will be passed in via an XML file to the dataURL parameter instead. The samples that Haibo provides also use a JavaScript file to wrap the calls to the Flash library and set the parameters.

So far, this looks fairly straightforward. The main question becomes: "How do you get the chart to display in the WebForm?" When I implemented the XML/SWF Chart sample, I did it for a standard client/server application using the Shockwave ActiveX in a window. However, the WebForm deploy doesn't support ActiveX controls, so some other mechanism must have been used. Even if that did work, that's not the way you'd want to implement it. Most browsers already have a Flash plugin available; you just want to provide the HTML to tell the browser to use that.

The solution is fairly simple, though not obvious. When you deploy an application to WebForms, a property called Embedded becomes available for the StaticHyperLink control. There's some discussion of it in the "Properties for .NET Web Forms" section of the HTML Books documentation for PowerBuilder. Otherwise, you wouldn't know about it. It's not mentioned in the WinHelp file, and the property pane for the control, the system browser, and the AutoScripting feature know nothing of it. When the property is set to true, instead of rendering as a hyperlink, the web page that is referenced is displayed within the IFRAME that is rendered at runtime for the control. Obviously you need to expand the size of the control to accommodate the page.

As a result, the code required to display the chart within the WebForm becomes fairly simple (see Listing 3). The n_cst_fusioncharts object is the object that Haibo created to do the heavy lifting for interacting with the FusionCharts library. In particular, its of_generatehtml_javascript and of_generatedataxml method are the methods used to generate the HTML and XML for the chart, respectively. The embedded property is then set to TRUE for the statichyperlink control and the URL assigned for the HTML page that was generated. The XML file that was generated is referenced within the HTML.

The of_generatehtml_javascript function dynamically generates the HTML based on the type of chart requested and some of its properties (see Listing 4).

The of_generatedataxml function is also worth looking at (see Listing 5). Because it's fairly large, it's only available online.

Regardless, if you're interested in generating next-generation charts in your WebForm applications, you should take a look at what Haibo has provided. The n_cst_fusioncharts object is already architected to do the majority of work for you. You only need to plug it into your application and start using it.

More Stories By Bruce Armstrong

Bruce Armstrong is a development lead with Integrated Data Services (www.get-integrated.com). A charter member of TeamSybase, he has been using PowerBuilder since version 1.0.B. He was a contributing author to SYS-CON's PowerBuilder 4.0 Secrets of the Masters and the editor of SAMs' PowerBuilder 9: Advanced Client/Server Development.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.