Topic: APLX Help : System Classes : The Chart and Series Objects : Customizing the Chart using the Draw method
[ Previous | Contents | Index | APL Home ]

www.microapl.co.uk

Customizing the Chart using the Draw method


You can add extra features to the display of a Chart object by using the Draw method. This works exactly as for other controls, allowing you to write text or add shapes such as polygons to the chart. When the Chart control is redrawn, it first renders the chart itself, and then runs your Draw method commands. (The same is true when the Chart object is printed, copied to the clipboard, or read back as a bitmap).

For this to be useful, you need to be able to relate your Draw commands to the chart itself. To assist in this, you can use the Chart object's Chartalttopoint Charttopoint Pointtochart Pointtochartalt methods, which allow you to convert between the X Y coordinates of the chart and the ordinary scale of the Chart control.

However, an easier way of ensuring that your Draw commands match up to the chart layout is to set the Draw command scale to 7, meaning 'use the Chart object's X and Y scales'. If you do this, all of your Draw commands will automatically be correctly rescaled if the chart is re-sized, as in this example where the Draw method is used to add circular coordinate lines to a polar chart (lines 26 to 30):

      ∇Chart_Polar;xdata;ydata;angle;radius;⎕IO;Polar
[1]  ⍝ Sample line chart used as a 'polar' chart
[2]  ⍝ Draw line where radius is a function of angle from horizontal
[3]   Polar←'⎕' ⎕NEW 'Window' ⋄ Polar.scale←5 ⋄ Polar.size←548 512
[4]   Polar.title←'Sample: Polar'
[5]   Polar.Chart.New 'Chart' ⋄ Polar.Chart.align←¯1
[6]   Polar.Chart.fonttitle←'APLX Upright'
[7]   Polar.Chart.title←'r = ⊖ (1 + sin ⊖)'
[8]   ⎕IO←0
[10]  angle←(⍳400)÷20
[11]  radius←angle×(1+1○angle)
[12]  ⍝
[13]  ⍝ Convert polar coordinates to XY coordinates
[14]  xdata←radius×2○angle
[15]  ydata←radius×1○angle
[16]  ⍝
[17]  ⍝ Set the scale to be ¯40 to +40 along both X and Y axes
[18]  Polar.Chart.xmajorticks←¯40 ¯30 ¯20 ¯10 0 10 20 30 40
[19]  Polar.Chart.ymajorticks←¯40 ¯30 ¯20 ¯10 0 10 20 30 40
[20]  ⍝
[21]  ⍝ Plot the data as though it were a line chart
[22]  Polar.Chart.s1.New 'series' ⋄ Polar.Chart.s1.xvalues←xdata
[23]  Polar.Chart.s1.yvalues←ydata ⋄ Polar.Chart.s1.linewidth←2
[24]  ⍝
[25]  ⍝ Use the Draw method to add circular reference lines
[26]  Polar.Chart.Draw 'Scale' 7            ⍝ Use Chart coordinates
[27]  Polar.Chart.Draw 'Pen' 1 200 200 200  ⍝ Light gray
[28]  Polar.Chart.Draw 'Mode' ¯1 9          ⍝ Mode 9 so that ticks show through     
[29]  Polar.Chart.Draw 'Brush' 0            ⍝ Transparent so circle not filled
[30]  Polar.Chart.Draw(⊂'Circle'),((⊂0 0),¨10×1+⍳4)
[31] ⍝
[32] ⍝ Wait until window is closed
[33]  0 0⍴⎕WE Polar
      ∇ 

This give the following effect, where the circular gray lines come from the Draw method commands:


Topic: APLX Help : System Classes : The Chart and Series Objects : Customizing the Chart using the Draw method
[ Previous | Contents | Index | APL Home ]