Thursday, September 7, 2023

πŸ’‘ BAM programs as "web services": The Pie Chart Service

(Nothing fancy in regards to pie-charting.  I aimed at just good enough for demonstration purposes !)


Although "web apps" would look better and perform better in pure javascript and CSS, I much prefer programming in BASIC.

This "Pie Chart Service" demonstrates how a BAM program, exported as a "Stand-Alone" program, can produce pie charts based on data provided to the program via a URL query string.

About "Stand-Alone" program export:

When you select the option to share a program as a stand-alone program, BAM exports to fairly small HTML file the BASIC program, the interpreter (i.e. all of the javascript code that interprets the BASIC program) and the HTML for the single-file web page to run in a web browser.

Share the exported HTML file by email or host it on the web, or store it locally for offline use.


The program accepts two parameters in the query string: screen mode (optional) and data.

Screen mode determines what colours are available to you in the pie chart.  The screen mode options are:

12 (0-12 will be treated as 12; no screen mode specified, 12 will be assumed)

This mode will provide a 16-color palette (colour mode "p16").  Black and white reserved for the program, that will leave you with 14 colours for your pie chart.  (See "About Colour Modes" for information about the ID numbers for the colours.)

17 (13-17 will be treated as 17)

This mode will provide a 64-color palette (colour mode "p256").  Black and white reserved for the program, that will leave you with 62 colours for your pie chart.  (See "About Colour Modes" for information about the ID numbers for the colours.)

27 (any number above 17 will be treated as 27)

If you want maximum flexibility for your colour choices, this mode allows for the 16,777,216 million colours available via RGB values.

To view the available colours for "p16" and "p256", visit the SCREEN Modes documentation and scroll down to the "colour modes" section.

Data defines the pie slices in the pie chart.  Each pie slice has two attributes: [1] a number indicating the size of the slice as a percentage of the entire pie (without the percent sign, i.e. just the number) and [2] the colour of the pie slice specified as a colour ID (for screen modes 12 and 17) or a hex number representing an rgb value (for screen mode 27). Every data value must be followed by a comma.

The program


To embed a pie chart in a web site, using the screen mode 17 sample:

<iframe src="https://basicanywheremachine.neocities.org/sample_programs/Pie%20Chart%20Service.prod.run?SCREEN=17&DATA=12,36,13,12,25,42,30,26,20,49," style="width:250px;height:250px;"> </iframe>





No comments:

Post a Comment

πŸ–₯ Fan Dance

This is a port and mod of a SpecBAS program by ZXDunny. Run the program View the source code And, a "less is more?" version: Run t...