DesignBais Tip – Alternative Graphs

How does an API work?

For the API, all of these products are developer tools. Most are intended for .NET, or Java developers. Some can be used from other languages like Perl, PHP, or Visual Basic. The way most of them work goes something like this:

  • Create some main object using the software.
  • Set values like
    obj.Title = “My Graph” and
    object.XaxisFontSize = 8
  • Set data in loops that resemble closely what you do with the DesignBais graph – you loop on data, adding it into the object
  • “Render” the object

The API for components is always defined in documentation. The internet is an excellent resource for examples, comments, bug info, etc. Sound familiar? We do the exact same thing when we get info from the manual to build the OUTPUT.zz variables in DesignBais.

That “rendering” part bears some more inquiry. Off hand I’ll say we’re talking about three different ways to render data. (Lot of lists here, eh? )

  1. With DesignBais, we create a dynamic array. On the web server, DesignBais code parses through our data, grabs what it needs, and loads the OWC object according to its specific API. This is a hardcoded process and we can’t substitute components. (This is done in bachart.asp, and no, the code is obfuscated so we can’t see it.)
  2. After population with data, the object is instructed to generate the chart as an image. The image is saved to disk as a file – JPEG, GIF, PNG, etc. ( I’ll bet some lights just went on! ) In particular, DB renders graphs as GIF images.
  3. OR… we can create a little web page which renders the graph into the page. I don’t suppose you’ve read my article on Client-side scripting, IFRAMEs, etc? Any more light bulbs?

Using the API

How do we get data into the API? Where does this “object” thing come from? Can we do this in BASIC? Wow, you ask a lot of questions! The answer is to do some coding outside of the MV environment. Data can be provided to the code in various ways. ( Oh no, not another list ! )

  • Write the data from MV to disk using OPENSEQ, D3 OSFI, or by whatever means you usually do this sort of thing. Most of us have written data to the host file system for email, FAX, or other purposes. The data can be tab delimited, XML, or formatted any way you want.. Once the data is written to disk, you can Execute or Perform a command to startup your graph-generating program which will:
    • create the object
    • read the data, parse it for individual values, and load the object
    • render to an image file or to HTML
  • You can use tools like mv.NET, UniObjects, UniObjects for Java, QMClient, or the D3 Class Library to reach from the web server into your MV environment to pull out the data.

All of the components listed above have a different API. Some of them must be dropped onto an ASP.NET web form and populated by .NET code (VB.NET, C#, etc). Some are ActiveX controls that must be dropped onto an HTML web page. Again, this doesn’t matter, as long as the process can be automated from start to finish.

Getting the graph into DesignBais

This is the simple part. If the only way to display the graph is to use HTML (rare case) then you can use the technique documented for client-side scripting and just put a little HTML page into your DesignBais form via a Text Only field. More commonly an API will have a Save function which allows for saving to disk. Create a unique ID, save the image to the web server and use DBIMAGESPEC to change the name of an Image field on a form so that it points to your new image. (We can’t use an absolute address for an image. All image references are relative to the DB virtual directory, \images. Otherwise you wouldn’t even need to save the image to the web server.)

Sometimes you need to work indirectly to get what you need from components like this. For example, I don’t think the jGRAPH component has a SaveAsJpeg type of feature, but once the graph is generated in the object it is as a Java BitmapImage, and that can be saved to disk. As you can see, the path taken for each one may be slightly different but the end result is the same.

You’ll need some housekeeping method to remove old images from disk. You might choose to create a directory for each user and clear it whenever the user logs in or out. You might use filenames with a date/time stamp and purge images older than some number of minutes or hours. DesignBais has a SESSION.ID variable that doesn’t change while a give user is logged-in – you may want to consider using that. You’ll need to work this out on an as-needed basis – it’s a lot like select lists which go “stale” and need to be cleared.

4 thoughts on “DesignBais Tip – Alternative Graphs

    • Interesting!
      I’m looking forward to seeing how I can use third party tools with DesignBais. I have previously wriiten .net apps using such tools – Dundas Charts and Telerik Controls – to provide graphically rich business information systems. I started out with OWC, but quickly move on from that because of the need for interactivity. There is also the requirement to have OWC installed on the server, and an Office licence to be consumed. Not normally an issue, but I’d guess the take-up of products like OpenOffice might be slightly higher than the norm in the, er, "financially astute" multivalue community.
      I’m hoping the experience with DesignBais isn’t going to be much more difficult than dropping a third party control onto a form in VS and setting a few properties in the aspx code behind page to hook the control up to an mv.net generated dataset. If its messy to do that ,and your app has a lot of charts rather than transactional data ,then you probably wouldn’t be using DesignBais. Horses for courses.

    • Phil, thanks for taking the time to comment. I understand everything you’re saying. I’ll write a small follow-up to this article soon regarding OWC licensing and possible errors which might compel someone to consider the alternatives discussed here.

      Running in an IFrame to an ASP.NET component can give us that interactive experience, but the DB form won’t be interactive with that chart without some diligent effort. It’s cool to have the chart right within the page, but it might be more elegant from a coding perspective to just launch a separate ASPX page, let the user do what they need interactively, save some state on the server via mv.NET or otherwise, and then have DB read that state back in a modal return event when the user closes their popup form.

      DesignBais is sort of intended to be a complete solution for people who don’t want the bells and whistles available in ASP.NET – or the related hassles. I think my ongoing message here is that there are those of us who appreciate DesignBais for what it is but we still want some of those extras – and I’m trying to show people how to get the best of both worlds. This turns the "either / or" and "horses for courses" position into a "best tools for the job" position, where DesignBais fits right in with whatever else we need to create the environment we want.

    • Tony
      I think we’re singing from the same hymn sheet here. I’m not that far down the road of working out what I can and can’t do with DesignBais (but I am intending to learn fast!), but I’ve been around long enough to know that there is ALWAYS a trade off between functionality and ease of use/speed of development, and also that these days developments (and web developments in particular) call for a mix of technologies. You can’t be too precious about any particular tool, you just have to be aware of the tools available and pick the best one for the job at hand. Now if one "swiss army knife" tool can get 80% of the job done, great.
      I see a parallel with the situation a couple of decades ago with Reality, where A*L*L was available as a 4GL. It was great at what it was good at, and you could rattle out apps if you knew how to use it, but for some things you just had to go back to DataBasic to get the job done. I’m hoping DesignBais will fill a similar role now, supplemented by mv.net/aspx/vb.net/Javascript etc for the complex, awkward or just plain flashy stuff.
      I’m starting to see what you mean by the comments made about getting excited about programming again.

    • People interested in this charting for DesignBais blog may also be interested in some new work that I’ve been doing:
      http://nebula-rnd.com/blog/tech/mv/2010/09/mvcharts1.html
      (So far there are Parts 1 and 2 of that “series”)

Leave a Reply