The i-Technology Media!
Register | Log in
   
 
.NET  ·  AJAX  ·  CLOUD  ·  ECLIPSE  ·  FLEX  ·  OPEN WEB  ·  iPHONE  ·  JAVA  ·  LINUX  ·  OPEN SOURCE  ·  ORACLE  ·  PBDJ  ·  SEARCH  ·  SILVERLIGHT  ·  SOA  ·  VIRTUALIZATION  ·  WEB 2.0  ·  WIRELESS  ·  XML
Comments
Google Wave Invitation Giveaway
By Aditya Banerjee
Timo Hirvonen wrote: I would really appreciate an invitation. Been desperately trying to find one :) timo [dot] hirvonen [at] gmail [dot]com
Nov. 27, 2009 11:13 AM EST
Cloud Expo on Google News
Did you read today's front page stories & breaking news?


2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts

2009 East
GOLD SPONSORS:
CA
Get Your Transactions Under Control: SOA Performance Management
Software AG
Performance Driven Adoption: The Secret to Advancing SOA
Intel
The Evolving SOA Appliance: 3 Game-Changing Innovations
SILVER SPONSOR:
Denodo
Data Mashups: Deliver Your Project Faster with Virtualized Data Services Across Internal & External Sources
POWER PANELS:
The Business Value of Service Orientation
Driving Profitability Through User Experience
Click For 2008 West
Event Webcasts
Live Google News by SYS-CON!
Top Three Links You Must Click On


Features
Using the Microsoft Chart Controls in PowerBuilder
Adding new charting capabilities to PowerBuilder applications

By: Bruce Armstrong
Aug. 27, 2009 08:45 AM

You may not be aware of this, but Microsoft now provides a rather powerful charting control free of charge as an add-in for .NET 3.5. It's available for download at http://xrl.us/ben3pm. Because it supports 35 different chart types (see Figure 1), it can add significant new charting capability to PowerBuilder applications.

As a .NET visual control we should be able to use it "natively" within PowerBuilder .NET targets once PB 12 is released. However, for those using the current (pre-12.0) versions of PowerBuilder, and those who will still be creating Win32 target applications even after moving to PB 12, it would still be nice to be able to use that control. This article will show you how to do that.

As with other .NET visual controls I've implemented in PowerBuilder in previous PBDJ articles, we'll be using the Microsoft Interop Forms Toolkit (http://xrl.us/beo995) to create a COM wrapper for the control. Once we've done that, we need to create methods, properties, and events on the wrapper that PowerBuilder will use to interact with the underlying control.

For example, there's no direct method for getting the data out of a PowerBuilder DataWindow and into the Microsoft Chart Control.

Even in DataWindow.NET, there's no good way of getting the data out of a DataWindow in the System.Data.Dataset object type that most .NET data-aware controls use. What I've done is created a SetData method on the wrapper that takes the data as an XML string, converts that to a DataSet, and then assigns that to the chart control:

public int SetData ( String xml)
{
System.IO.StringReader sr;
sr = new System.IO.StringReader(xml);
dataset.ReadXml(sr);
chart.DataSource = dataset;
chart.DataBind();
return 1;
}

In addition, the chart type value for the control is set through an enumerated value on a .NET class. Since PowerBuilder can't use that in a Win32 target, I created a method on the wrapper that takes the chart type designed as a string and then determines the applicable enumerated value based on it:

public int SetChartType(String type)
{
switch(type)
{
case "Area":
series.ChartType = SeriesChartType.Area ;
break;
case "Bar":
series.ChartType = SeriesChartType.Bar;
break;
case "BoxPlot":
series.ChartType = SeriesChartType.BoxPlot;
break;
.
.
.
default:
series.ChartType = SeriesChartType.Line ;
break;
}
return 1;
}

In PowerBuilder, I created a new Standard User Object of type olecontrol, and then indicated that I want to base it on the InteropUserControl wrapper I created. I can create additional wrapper functions on this user object that make the control more "PB friendly." Now I have a visual user control I can drop onto any window in any application.

In the example code that you can download from the PBDJ site, I'm using the following code to initially create the chart in the sample window:

string                           ls_xml
u_ds_salaries               lds_salaries

lds_salaries = CREATE u_ds_salaries
ls_xml = lds_salaries.Object.DataWindow.Data.XML
Destroy lds_salaries

ole_chart.of_setdata( ls_xml )
ole_chart.of_addseries( "Salaries" )
ole_chart.of_setXseries( "emp_lname" )
ole_chart.of_setYseries( "salary" )
ole_chart.of_Setcharttype( "Line" )

u_ds_salaries is just a datastore user object that contains a DataWindow that contains employee data from the PowerBuilder example database. I've stored the data in the DataWindow so that you don't need to worry about configuring a database connection to run the sample. There are also a number of minor wrapper functions being called on the interop user control that I haven't mentioned here for brevity. In this particular sample, when the user selects a different graph type from the radio buttons, I just pass the new chart type selected to the SetChartType method.

That's all there is to it. About 300 lines of C# code that I had to add to the interop control, and significantly less than that in the PowerBuilder sample. Obviously, you'll want to extend the control to make use of more of the underlying functionality of the Microsoft Chart Controls, but the sample should give you a significant start.

Published Aug. 27, 2009— Reads 1,444 — Feedback 1
Copyright © 2009 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
About 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.

Add Your Feedback

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

#1
Dimitri Joosten commented on 8 Sep 2009

Hi Bruce, this technique is very usefull! I am evaluating it now and see how I can use it in the (near) future! Thanks!


Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers

ADS BY GOOGLE

Breaking Java News
Cagim Announces Increase in Results for Second Quarter of Fiscal Year 2009
Chai-Na-Ta Corp. Reports 2009 Third Quarter Results
Statement of Condolence-Nelson Leeson, President of the Nisga'a Lisims Government
T.G.I. Friday's(R) Restaurants Announce Gift Card Giveaway
Media Advisory: New National Research Council, University of Ottawa Laboratory Home to Canada's Fastest X-Ray Laser
November Is Pulmonary Hypertension Awareness Month
Atlantic Power Corporation Completes Conversion to Traditional Common Share Structure
Sigma Designs, Inc. Schedules Conference Call to Discuss Fiscal Third Quarter Financial Results
Crown Minerals Increases Size of Non-Brokered Private Placement
Petra Petroleum Inc.: News Release

ADVERTISE   |   MAGAZINE SUBSCRIPTIONS   |   FREE BREAKING-NEWSLETTERS!   |   SYS-CON.TV   |   BLOG-N-PLAY!   |   WEBCAST   |   EDUCATION   |   RESEARCH

.NET Developer's Journal - .NETDJ   |   ColdFusion Developer's Journal - CFDJ   |   Eclipse Developer's Journal - EDJ   |   Enterprise Open Source Magazine - EOS
Open Web Developer's Journal - OPENWEB   |   iPhone Developer's Journal - iPHONE   |   Virtualization - Virtualization   |   Java Developer's Journal - JDJ   |   Linux.SYS-CON.com
PowerBuilder Developer's Journal - PBDJ   |   SEO / SEM Journal - SJ   |   SOAWorld Magazine - SOAWM   |   IT Solutions Guide - ITSG   |   Symbian Developer's Journal - SDJ
WebLogic Developer's Journal - WLDJ   |   WebSphere Journal - WJ   |   Wireless Business & Technology - WBT   |   XML-Journal - XMLJ   |   Internet Video - iTV
Flex Developer's Journal - Flex   |   AJAXWorld Magazine - AWM   |   Silverlight Developer's Journal - SLDJ   |   PHP.SYS-CON.com   |   Web 2.0 Journal - WEB2
Apache   |   CMS   |   CRM   |   HP   |   Oracle Journal   |   Perl   |   Python   |   Red Hat   |   Ruby on Rails   |   SAP   |   SaaS

SYS-CON MEDIA:   ABOUT US   |   CONTACT US   |   COMPANY NEWS   |   CAREERS   |   SITE MAP
SYS-CON EVENTS:   |  AJAXWorld Conference & Expo  |  iPhone Developer Summit  |  Cloud Computing Conference & Expo  |  SOA World Conference & Expo  |  Virtualization Conference & Expo
INTERNATIONAL SITES:   India  |  U.K.  |  Canada  |  Germany  |  France  |  Australia  |  Italy  |  Spain  |  Netherlands  |  Brazil  |  Belgium
 Terms of Use & Our Privacy Statement     About Newsfeeds / Video Feeds
Copyright ©1994-2008 SYS-CON Publications, Inc. All Rights Reserved. All marks are trademarks of SYS-CON Media.
Reproduction in whole or in part in any form or medium without express written permission of SYS-CON Publications, Inc. is prohibited.
 
close this window