ClassPackage: cgToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 8.2
Unrevised from 8.1 to 8.2.
8.1 version

chart-widget

The class of the chart-widget.

The chart-widget is a versatile facility for creating two-dimensional line graphs and bar charts. (To plot X/Y coordinate pairs instead, see the plot-widget class.)

The chart widget could be used to present static information or to dynamically monitor information as it changes. The widget will automatically lay out its axes and other parts (according to style properties that you can modify) and can also autocompute a rounded value range that encloses all of the data values. A long sequence of data items can be scrolled into view by dragging the mouse or using the usual scrolling keys.

Chart subobjects

The following classes are used to create secondary objects that are used by a chart-widget:

Each of these classes has its own properties (that is, slots and accessors).

Properties of the chart-widget class

These properties are unique to the chart-widget class.

Additional chart-widget properties are provided by the chart-or-plot superclass.

chart-widget example

Below is a quick chart-widget example. See the chart-widget tutorial (cg-chart-widget.htm) for more examples with more extensive explanations. The tutorial is probably the best way to learn the widget. There is also an example in the IDE's Navigator Dialog that generates random charts to show off the variety of its styles.

The following example code demonstrates the two main alternate techniques for supplying the data for a chart: (1) calling set-chart-value once for each datum, and (2) supplying a chart-value-returner function that will be called as needed to return each value.

For both techniques we will use the following sample data. Each of the entries in this list will become one "chart item" for a bowling event, and each person that is mentioned in the plists of bowling scores will become one "chart object".

(defparameter *scores*
  '(((2005 dec 12) :doris 164 :tal 152)
    ((2006 feb 3) :doris 168 :tal 145 :hubert 103)
    ((2006 feb 18) :doris 160 :tal 173 :hubert 110 :myrtle 124)
    ((2006 jun 17) :doris 172 :tal 160 :myrtle 142)
    ((2006 aug 31) :tal 170 :myrtle 135)))

The first version of the example code uses the approach of calling set-chart-value for each datum, after creating the chart-widget.

(let* ((width 300)
       (height 400)
       (chart-widget
        (make-instance 'chart-widget
          :title "Bowling Scores"
          :chart-view :line
          :fit-chart-items t
          :item-axis (make-instance 'item-axis
                       :on-print-major-label
                       (lambda (date)
                         (format nil "~:(~a~) ~a ~a"
                           (second date)(third date)(first date))))
          :chart-legend (make-instance 'chart-legend
                          :on-print-chart-object 'capitalize-object)
          :right-attachment :right
          :bottom-attachment :bottom
          :left 0 :top 0 :width width :height height))
       (dialog (make-window :bowling-scores
                 :class 'dialog
                 :title "Bowling Scores"
                 :scrollbars nil
                 :interior (make-box-relative 40 40 width height)
                 :dialog-items (list chart-widget)))
       item-id)
  (dolist (item *scores*)
    (setq item-id (pop item))
    (loop (unless item (return))
          (set-chart-value
           chart-widget
           :item-id item-id
           :object-id (first item)
           :value (second item))
          (setq item (cddr item))))
  dialog)

The second version builds the same chart by supplying a chart-value-returner function rather than by calling set-chart-value in a loop. When using a chart-value-returner, you generally need to supply a list of chart-objects and a chart-items-max-index to tell the widget the range of items and objects for which it should query values.

(let* ((width 300)
       (height 400)
       (chart-widget
        (make-instance 'chart-widget
          :title "Bowling Scores"
          :chart-view :line
          :fit-chart-items t
          :item-axis (make-instance 'item-axis
                       :on-print-major-label
                       (lambda (date)
                         (format nil "~:(~a~) ~a ~a"
                           (second date)(third date)(first date))))
          :chart-legend (make-instance 'chart-legend
                          :on-print-chart-object 'capitalize-object)
          :chart-objects '((:id :doris)(:id :hubert)(:id :myrtle)(:id :tal))
          :chart-items-max-index (1- (length *scores*))
          :chart-value-returner
          (lambda (chart-widget value-type item-index
                                object-index object-id)
            (declare (ignore chart-widget object-index))
            (let* ((item (nth item-index *scores*)))
              (case value-type
                (:id (first item))
                (:value (getf (rest item) object-id)))))
          :right-attachment :right
          :bottom-attachment :bottom
          :left 0 :top 0 :width width :height height)))
  (make-window :bowling-scores
    :class 'dialog
    :title "Bowling Scores"
    :scrollbars nil
    :interior (make-box-relative 40 40 width height)
    :dialog-items (list chart-widget)))

See cg-chart-widget.htm.


Copyright (c) 1998-2012, Franz Inc. Oakland, CA., USA. All rights reserved.
Documentation for Allegro CL version 8.2. This page was not revised from the 8.1 page.
Created 2010.1.21.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 8.2
Unrevised from 8.1 to 8.2.
8.1 version