Implemented on desktop editions of APLX only
ŚCHART provides a quick way of drawing a chart (graph) of data in an APL array. The right argument is the data to be plotted, which can comprise one or more data series. The optional left argument is a set of keyword/value pairs which allow you to customize the appearance of the chart. The chart appears in a new window. Once it has appeared, you can use the menu bar to alter the way in which it is displayed (for example, to switch to a logarithmic Y scale).
ŚCHART is designed to provide automatic graph-drawing facilities with very little programming effort. If you wish to have full control over how the chart is drawn, you should instead use the Chart object under ŚWI. You can also chart data by right-clicking over the name of a variable and selecting 'Display As Chart' from the pop-up menu, or by choosing 'Chart Variable..' from the Edit menu of the session window.
The right argument to ŚCHART is the data to be charted. It can be any of the following:
The optional left argument to ŚCHART allows you to the determine how the chart is displayed. (If you omit it, APLX uses the above rules initially, and then the parameters can be adjusted using the Chart menu.)
It comprises a nested vector of one or more phrases of the form 'Keyword=Value'. (If there is only one such phrase, the argument can be a simple character vector). The options are as follows (case is ignored in checking the keywords):
title - Sets the title for the whole chart, for example 'title=Absorbtion of Calcium'
type - Sets the type of graph, for example 'type=area'. The value part of this phrase should be one of the following: line scatter area bar stair horizbar or pie. If you omit this phrase, a Line chart is drawn initially, unless the right argument is nested, in which case a Bar chart is drawn. Once the chart has appeared, you can change the type using the Chart menu.
data - Specifies how the data is laid out in the right argument, for example 'data=rows'. The value part of this phrase should be one of the following: rows (the data points are along the rows of the right argument, or columns or cols (the data points are laid out down the columns of the right argument). If you omit this phrase, APLX uses the rules described above. Again you can adjust the choice once the chart has been drawn.
x - Specifies which data set contains the X values. This can one of first (the X values are in the first row or column of the right argument), last (the X values are in the last row or column of the right argument), or implicit (all the rows/columns contain Y values, which should be plotted against 0, 1, 2...). If you omit this phrase, APLX tries to guess the most likely layout using the rules described above.
seriesname - Allows you to specify a label to be attached to each series of the graph. You will normally want to repeat this phrase several times, once for each series in the chart. For example, if you wanted a chart showing sales for three regions against an implicit X axis of 0,1 2, you could provide an N by 3 array as the right argument, and for the left argument specify: 'seriesname=America' 'seriesname=Europe' 'seriesname=Asia' 'x=implicit'. The data in the first row would be labelled 'America', the second 'Europe', and the third 'Asia'.
The 'id' keyword can be used to tell ŚCHART to re-use an existing chart window to graph new data. This can be useful if you want to do simple animations, for example display a graph of changing data acquired from an external measuring device in real time.
The keyword takes the form 'id=N', where N is a positive integer. When the id keyword is specified, ŚCHART will check whether there is already a chart window with the same id, creating a new window only if one is not found (See examples).
Tip: If you want to chart a variable, and have the chart change when the variable changes (in desk calculator mode), you can use an expression like this in a Watch window:
'id=1' ŚCHART X
Draw a sine wave. Because no X values are specified, implicit X values of 0, 1, .... 99 are used:
ŚCHART 1±0.1׼100
Draw a sine wave with the X values specified in degrees. We provide a two-column matrix; APLX assumes the second column is the X axis, because it increments regularly:
ŚIO„1 ŚCHART (1±(10×0,Ľ36)×±2÷360),[1.5]0,10׼36
Draw a bar chart:
ŚCHART 2 4˝'Apples' 'Pears' 'Oranges' 'Kumquats' 445 323 345 765
Draw the same data as a pie chart:
'type=pie' ŚCHART 2 4˝'Apples' 'Pears' 'Oranges' 'Kumquats' 445 323 345 765
Draw some random data as two, named series, against implicit X values 0, 1, 2..:
'x=implicit' 'seriesname=Bicycles' 'seriesname=Tricycles' ŚCHART ?2 8˝100
Draw an animated graph
’AnimatePulse;pulse;X [1] pulse„(*-X÷10)×1±4×X„Ľ100 © Create some fake data [2] pulse„(˛pulse),pulse [3] :Repeat [4] 'id=1' ŚCHART pulse [5] pulse„2˛pulse [6] :EndRepeat ’
See also the Chart and Series system classes, which give you much more detailed control over the layout and appearance of graphs.