line_chart
NAME
line_chart(): Generate an ASCII multi-line chart based on an arbitrary query.TYPE
ProcedureDESCRIPTION
Given an arbitrary query, generate a poor man's ASCII multi-line chart visualizing query's data. Visualization includes multi-line plot, x-axis extreme values, y-axis approximated values and an optional legend.
Height of query is currently fixed, and width of query varies by amount of returned rows.
SYNOPSIS
line_chart( IN values_query TEXT, IN chart_legend TEXT ) READS SQL DATA
Input:
-
values_query: a query producing data to be visualized. Query columns are
assumed as follows:
- First column makes for "x" values. line_chart() will sort the results by first column ascending. The type of this column is arbitrary; it could be numerical, temporal etc.
- 2nd [, 3rd [...]] columns are "y" values. You may provide up to
8 data columns, totaling 9 columns together with
the first "x" values column. Note, however, that due to low ASCII plotting
resolution, more columns make for less readable visualization.
Values of these columns are expected to be numerical.
-
chart_legend: comma delimited text, listing the desired
legend items. There should be the same number of tokens in this parameter as there
are data columns in the query. However, line_chart() will work with less that
number or more; the result of a nonmatching number is a nonmatching legend.
You may pass NULL or '' (empty text) to avoid displaying a legend.
EXAMPLES
Show a simple sine & log computation:
mysql> call line_chart("select n, log(n), sin(n/5)+2 from numbers where n > 0 order by n limit 80", "log n, 2 + sin n/5"); +---------+----------------------------------------------------------------------------------+ | y_scale | common_schema_chart | +---------+----------------------------------------------------------------------------------+ | 4.38 | ---------------------------------------------------------------------########### | | 4.11 | -----------------------------------------------------################----------- | | 3.83 | ----------------------------------------#############--------------------------- | | 3.56 | ------------------------------##########---------------------------------------- | | 3.29 | -----------------------#######-------------------------------------------------- | | 3.01 | -----*****-------######-------------*****---------------------------*****------- | | 2.74 | ---**-----**-####-----------------**-----**-----------------------**-----**----- | | 2.46 | -**-------##**-------------------*---------**-------------------**---------*---- | | 2.19 | *------###----*----------------**------------*-----------------*------------**-- | | 1.92 | -----##--------*--------------*---------------**-------------**---------------*- | | 1.64 | ----#-----------**----------**------------------*-----------*------------------* | | 1.37 | ---#--------------**-------*---------------------**-------**-------------------- | | 1.10 | --#-----------------*******------------------------*******---------------------- | | 0.82 | -#------------------------------------------------------------------------------ | | 0.55 | -------------------------------------------------------------------------------- | | 0.27 | -------------------------------------------------------------------------------- | | 0.00 | #------------------------------------------------------------------------------- | | | v::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::v | | | 1 80 | | | # log n | | | * 2 + sin n/5 | +---------+----------------------------------------------------------------------------------+