Class: SVG::Graph::Pie

Class SVG::Graph::Pie |
In: | temp/Graph/Pie.rb
Parent: | Graph

# SVG::TT::Graph::Pie

### Create presentation quality SVG pie graphs easily

## Synopsis

      require 'SVG/Graph/Pie'

      fields = %w(Jan Feb Mar)
      data_sales_02 = [12, 45, 21]

      graph = SVG::Graph::Pie.new({
              :height => 500,
        :width  => 300,
        :fields => fields,
      })

      graph.add_data({
              :data => data_sales_02,
        :title => 'Sales 2002',
      })

      print "Content-type: image/svg+xml\r\n\r\n"
      print graph.burn();

## Description

This object aims to allow you to easily create high quality SVG pie graphs. You can either use the default style sheet or supply your own. Either way there are many options which can be configured to give you control over how the graph is generated - with or without a key, display percent on pie chart, title, subtitle etc.

## See also

- SVG::Graph::Graph
- SVG::Graph::BarHorizontal
- SVG::Graph::Bar
- SVG::Graph::Line
- SVG::Graph::Plot
- SVG::Graph::TimeSeries

Methods

add_data set_defaults

Attributes

datapoint_font_size | [RW] | The font size of the data point labels
expand_gap | [RW] | The amount of space between expanded wedges
expand_greatest | [RW] | If true, expand the largest pie wedge
expanded | [RW] | If true, "explode" the pie (put space between the wedges)
shadow_offset | [RW] | Sets the offset of the shadow from the pie chart
show_actual_values | [RW] | If true, display the actual field values in the data labels
show_data_labels | [RW] | If true, display the data labels on the chart
show_key_actual_values | [RW] | If true, display the actual value of the field in the key
show_key_data_labels | [RW] | If true, display the labels in the key
show_key_percent | [RW] | If true, display the percentage value of the wedges in the key
show_percent | [RW] | If true, display the percentage value of each pie wedge in the data labels
show_shadow | [RW] | If true, displays a drop shadow for the chart

Public Instance methods

set_defaults()

Defaults are (those supplied with Graph)

show_shadow
  true
shadow_offset
  10
show_data_labels
  false
show_actual_values
  false
show_percent
  true
show_key_data_labels
  true
show_key_actual_values
  true
show_key_percent
  false
expanded
  false
expand_greatest
  false
expand_gap
  10
show_x_labels
  false
show_y_labels
  false
datapoint_font_size
  12

add_data(arg)

Adds a data set to the graph.

      graph.add_data( { :data => [1,2,3,4] } )

Note that the :title is not necessary. If multiple data sets are added to the graph, the pie chart will display the `sums` of the data. EG:

      graph.add_data( { :data => [1,2,3,4] } )
      graph.add_data( { :data => [2,3,5,9] } )

is the same as:

      graph.add_data( { :data => [3,5,8,13] } )