Topic: APLX Help : System Classes : The Chart and Series Objects : Using the Chart Object
[ Previous | Next | Contents | Index | APL Home ]

www.microapl.co.uk

Using the Chart Object


The main steps you need to carry out to create a chart are as follows:

  1. Create a Chart object, typically setting the chart type using the type property, and as appropriate setting labels for the chart title, axis labels, etc.

  2. Create one or more Series objects, as children of the Chart object, and use these to specify the data which the chart will display. You can specify the data in various ways, typically using the values property, or the xvalues and yvalues properties separately.

  3. Optionally, customize the chart's appearance by setting various properties of the Chart object. You can also set various properties of the child Series objects (for example, to set the colors used to display each series).

The Chart object responds dynamically to each change you make. (You can switch this off using the update property). So, having created a chart, you can for example convert a line chart to an area chart by changing the type property.


Here is an example of a function which produces a simple chart showing two different series:

     ∇Chart_Microsoft;MS;data;years;revenue;income;⎕IO
[1] ⍝ Sample line chart
[2]  MS←'⎕' ⎕NEW 'Window' ⋄ MS.title←'Sample chart'
[3]  MS.Chart.New 'Chart' ⋄ MS.Chart.align←¯1 ⋄ MS.Chart.type←'line'
[4]  MS.Chart.title←'Microsoft Financials FY 1985-2004'
[5]  MS.Chart.yaxislabel←'$ Millions'
[6] ⍝
[7]  MS.Chart.s1.New 'series' ⋄ MS.Chart.s1.caption←'Revenue'
[8]  MS.Chart.s2.New 'series' ⋄ MS.Chart.s2.caption←'Net Income'
[9] ⍝
[10] ⍝ Set up data
[11] ⎕IO←0
[12] years←1985+⍳20
[13] revenue←140 198 346 591 805 1186 1847 2777 3786 4714 6075
[14] revenue←revenue,9050 11936 15262 19747 22956 25296 28365 32187 36835
[15] income←24 39 72 124 171 279 463 708 953 1146 1453
[16] income←income,2195 3454 4490 7785 9421 7346 5355 7531 8168
[17] ⍝
[18] MS.Chart.s1.yvalues←revenue ⋄ MS.Chart.s1.xvalues←years
[19] MS.Chart.s2.yvalues←income ⋄ MS.Chart.s2.xvalues←years
     ∇

This produces a window which contains the following chart:

(Note that the number of ticks and labels shown may vary as the window is resized).

We can now customize the Chart object in various ways. For example, we can use the style property to display a grid, the subtitle property to add a subtitle, and the note property to add a note:

     MS.Chart.subtitle←'(since IPO)'
     MS.Chart.note←'Source: Microsoft Inc'
     MS.Chart.style←(1+8)

The graph will now look like this:

We can also set attributes of the individual series. For example, we might want the 'Net Income' line to be displayed as a dotted line, in green:

    MS.Chart.s2.linetype←2
    MS.Chart.s2.color←0 180 0


Topic: APLX Help : System Classes : The Chart and Series Objects : Using the Chart Object
[ Previous | Next | Contents | Index | APL Home ]