|
|||||||||||||||
e've all seen Web sites that display great-looking, informative graphs generated from dynamic data. Stock market reports are one common example of these; sales and marketing information also frequently get this treatment. The graphs are not HTML-generated clunky bar graphs but are actually graphic images—GIFs or JPEGs—that use data generated from an ASP page—dynamically.
How can you do it too? In this 10-Minute Solution I describe how to generate graphs from an ASP page so you'll never again have to jump through hoops with ASP code to generate static HTML displays. You'll finally have the know-how to give your business data the slick, professional display that it merits.
Survey Your Options My method has a hidden advantage: I've already done all the work for you. Remember, bad programmers write code . . . good programmers steal . . . er, borrow! The key to my method is to leverage the very robust and capable ChartWizard included in Microsoft Excel. The plan is to obtain our data from the user or from the database and then use Microsoft Excel to generate our graphs. We then display this Excel chart on our web page. Simple? Yes, and you only need know a few things about the Excel ChartWizard.
Prepare Your Environment Before You Begin If you are running Microsoft Internet Information Server (IIS) 4 on Windows NT you will need to change the parameters of the IIS metabase to allow out-of-process components to run on your site. This is required for your ASP page to invoke and automate the Microsoft Excel EXE. Details of this are provided by Microsoft in the article "Enabling the Use of Out-of-Process Components in ASP Using the Metabase" on MSDN Online.
The Application in Action When the user clicks the button 'Generate Chart,' the values are charted and the same page returns but this time as a chart (see Figure 2).
Obtain the Data for the Chart To simply obtain information from our users, we create a form with 12 text boxes to hold the 12 monthly values and another one to hold the company name. We do this within an HTML form construct as follows:
As you can see, we display the text box for the name of the company first using the <INPUT> tag with a default value of 'Microsoft':
We then display 12 labels and 12 text boxes underneath it. Rather than hard code the tags 12 times, we loop through a counter variable and create our HTML. To generate the dates, we use the FormatDateTime function with a second argument of 2 to return a short date format. We also generate 12 text boxes with names v1 to v12 in the same loop.
You will notice in the above code a hidden variable called "pass." The pass variable is my favorite way to determine whether this is the first time the page has been viewed or if the user is returning to the form after it has been submitted. If it is the first time, you can seed the text box with random, pre-filled values, which means the user isn't forced to enter values.
|
|||||||||||||||
|