Let's start with the widely known statistical Bar graphic:
Code: Select all
@echo off
::Statistical Bar Graph drawing
::Antonio Perez Ayala - Jan/03/2012
setlocal EnableDelayedExpansion
set Set1=10 11 12 13 14 15 16 17 18 19 20 21
set Set2=24 22 20 18 16 14 16 18 20 22 24 26
set Set3=24 23 22 21 20 19 18 17 16 15 14 13
set Set4=14 16 18 20 22 24 22 20 18 16 14 12
set Set5=10 10 10 10 10 10 10 10 10 10 10 10
set SetNames=GROWING "DOWN TO UP" SHRINKING "UP TO DOWN" FLAT
set ValueNames=Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
cls
echo/
echo T H I S I S T H E T I T L E O F T H E B A R G R A P H
echo/
call :DrawBarGraph 34 Set SetNames ValueNames
goto :EOF
:DrawBarGraph BarHeight SetsVar SetsNamesVar ValueNamesVar
rem Separate and count SetsVar elements
set /A maxV=0, numJ=9999, i=1
:nextSet
set j=0
for %%v in (!%2%i%!) do (
set /A j+=1
set V%i%.!j!=%%v
if %%v gtr !maxV! set maxV=%%v
)
if %j% lss %numJ% set numJ=%j%
set /A i+=1
if defined %2%i% goto nextSet
set /A numI=i-1
rem Map elements to fit the graph
for /L %%i in (1,1,%numI%) do (
for /L %%j in (1,1,%numJ%) do (
set /A V%%i.%%j=V%%i.%%j * %1 / %maxV%
)
)
rem Show set names
set i=0
for %%c in (█ ░ ▓ ▄ ▒) do (
set /A i+=1
set C!i!=%%c
)
set /A nameWide=(80/(numI+1))/2
set nameSep=
for /L %%n in (1,1,%nameWide%) do set nameSep= !nameSep!
set /P =%nameSep%< NUL
set nameSep=%nameSep%%nameSep%
set /A nameWide*=2, i=0
for %%n in (!%3!) do (
set /A i+=1
set name=%%~n%nameSep%
for %%i in (!i!) do set /P =!C%%i! !name:~0,%nameWide%!< NUL
)
echo/
echo/
echo/
rem Get wide of left margin, bars and separators
set /A barWide=80/(numI*numJ)
if %barWide% gtr 10 set barWide=10
if %barWide% gtr 2 set /A barWide-=1
set /A nameWide=barWide*numI
set /A sepWide=(80-nameWide*numJ)/(numJ-1), leftWide=(80-nameWide*numJ-sepWide*(numJ-1))/2, nameWide+=sepWide
set leftBar=
for /L %%w in (1,1,%leftWide%) do set leftBar= !leftBar!
set sepBar=
for /L %%w in (1,1,%sepWide%) do set sepBar= !sepBar!
rem Draw the Bar Graph
for /L %%v in (%1,-1,1) do (
set /P =%leftBar%< NUL
for /L %%j in (1,1,%numJ%) do (
for /L %%i in (1,1,%numI%) do (
if !V%%i.%%j! geq %%v (
for /L %%w in (1,1,%barWide%) do set /P =!C%%i!< NUL
) else (
for /L %%w in (1,1,%barWide%) do set /P = < NUL
)
)
set /P =%sepBar%< NUL
)
echo/
)
rem Show value names
echo/
set nameSep=
for /L %%n in (1,1,%nameWide%) do set nameSep= !nameSep!
set /P =%leftBar%< NUL
set i=0
for %%n in (!%4!) do (
set /A i+=1
set name=%%~n%nameSep%
for %%i in (!i!) do set /P =!name:~0,%nameWide%!< NUL
)
echo/
exit /B
Results:
Code: Select all
T H I S I S T H E T I T L E O F T H E B A R G R A P H
█ GROWING ░ DOWN TO UP ▓ SHRINKING ▄ UP TO DOWN ▒ FLAT
░
░
░
░▓ ▄ ░ ░
░▓ ▓ ▄ ░ ░
░▓ ▓ ▄ ░ ░
░▓ ░▓ ▓ ▄ ▄ ▄ ░ ░ ░
░▓ ░▓ ▓ ▓ ▄ ▄ ▄ ░ ░ █░
░▓ ░▓ ░▓ ▓▄ ▓▄ ▄ ▄ ▄ ░ ░ █░ █░
░▓ ░▓ ░▓ ▓▄ ▓▄ ▄ ▄ ▄ ░ ░ █░ █░
░▓ ░▓ ░▓ ▓▄ ▓▄ ▓▄ ▄ ▄ ░ █░ █░ █░
░▓ ░▓ ░▓▄ ░▓▄ ▓▄ ▓▄ ▓▄ ░ ▄ █░ ▄ █░ █░ █░
░▓ ░▓ ░▓▄ ░▓▄ ▓▄ ▓▄ ▓▄ █░▓▄ █░ ▄ █░ █░ █░
░▓ ░▓ ░▓▄ ░▓▄ ▓▄ ▓▄ ▓▄ █░▓▄ █░ ▄ █░ █░ █░
░▓ ░▓▄ ░▓▄ ░▓▄ ░▓▄ ▓▄ █░▓▄ █░▓▄ █░▓▄ █░ ▄ █░ █░
░▓ ░▓▄ ░▓▄ ░▓▄ ░▓▄ █ ▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░ █░
░▓▄ ░▓▄ ░▓▄ ░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░
░▓▄ ░▓▄ ░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓
░▓▄ ░▓▄ ░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓
░▓▄ ░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄
░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄ █░▓▄
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
█░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒ █░▓▄▒
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec