Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Simplify and Enhance Your Reporting with Character-based Bar Charts : Page 3

Numerous software packages and programming languages have built-in capabilities for producing text-based bar charts by making use of either ASCII or UNICODE characters. Because these bar graphs are nothing more than text characters themselves, you don't need any special third-party software to create them. Consequently, you can incorporate such graphs easily and at virtually no cost anywhere you need to present tabular data.


advertisement
Producing Characters
The rendering of text characters to create bar charts is, of course, dependent on the font used. While the "what" to be displayed is derived from the actual character chosen from the ASCII or Unicode character set, the "how" is the result of the font used. For example, the percent character (%) in an Arial font looks slightly different from the same character in Times New Roman. Also, be aware that not all fonts support all characters sets (especially the emerging Unicode character set. However, most newer fonts do).

You can type the bars directly into documents, store a character in a variable so you can use it on demand whenever needed, or generate the character dynamically using a formula or function. Most tools and languages have built-in functions for generating ASCII and Unicode characters. The last method is the most flexible, because you can use conditional formatting to create the chart.

In summary, Table 1 below lists several popular programs and languages that have such functions for generating characters.

Table1. Built-in functions for generating characters dynamically where X = the numeric character code (decimal format).

Program or Language

ASCII



UNICODE

Crystal Reports

chr(X)

Unicode not supported

HTML

&#X;

&#X;

Java

(char)X

(char)X

JavaScript

String.fromCharCode(X)

String.fromCharCode(X)

Lotus Notes (Formula Language)

@char(X)

no built-in function

Lotus Notes (Lotus Script)

 chr(X)

uchr(X)

Microsoft Access

chr(X)

chrw(x)

Microsoft Excel

char(X)

no built-in function

Oracle

chr(X)

nchr(X)

Perl

chr(X)

chr(X)

PHP

chr(X)

no built-in function

SAS

byte(X)

no built-in function

S-Plus

no built-in function

no built-in function

SPSS

no built-in function

no built-in function

SQL Server

char(x)

nchar(X)

Visual Basic (incl. VBA, VBScript)

chr(X)

chrw(x)


It is worth noting that just because a program or language does not have a built-in function to dynamically create ASCII or Unicode characters does not necessarily mean that you can't use these special characters—you'd just need to store them in string variables or type them in manually.

Repeating Characters
Now for the fun part. After creating or selecting a symbol you need to repeat it as many times as needed. In the cola example above, the calculation used the average rating (1-5) of each brand. In a different application, where there is no bound on the maximum value, the number of characters might be the actual count and not a ratio of the maximum (possible) value. Regardless, the number of characters to plot will be dictated in the context of the problem. In some applications, the number will be known and fixed (like an executive summary email to shareholders). In other applications, like a database query, the number will change dynamically per record. Thus, there are two ways to create repeating characters:static and dynamic.

In either case, many programs and languages also have built-in functions for repeating characters a specified number of times. When the number of times to repeat needs to be dynamically set, you can pass the parameter by reference to another variable, such as a spreadsheet cell reference. But even if a program or language doesn't have a native function to create a string containing a specific number of characters, you can use a looping routine in a user-defined function that repeatedly concatenates your symbol character onto a string variable until it has grown to the desired length. Table 2 illustrates the various built-in functions in several common packages and languages.

Table2. Built-in functions for repeating characters a specified number of times where c = character (i.e. could be a string literal, a variable, a spreadsheet cell reference, or a database field), and n = number of times to repeat character (i.e. could be also be a variable, cell reference, or database field)

Program or Language

Function

Crystal Reports

ReplicateString(c,n)

HTML

no built-in function

Java

no built-in function

JavaScript

no built-in function

Lotus Notes (Formula Language)

@repeat(c;n)

Lotus Notes (Lotus Script)

ustring(n,c)

Microsoft Access

string(n,c)

Microsoft Excel

rept(c,n)

Oracle

no built-in function

Perl

no built-in function

PHP

str_repeat(c,n)

SAS

repeat(c,n)

S-Plus

no built-in function

SPSS

no built-in function

SQL Server

replicate(c,n)

Visual Basic (incl. VBA, VBScript)

string(n,c)



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date