001    /*
002     * This file is part of the Echo Point Project.  This project is a
003     * collection of Components that have extended the Echo Web Application
004     * Framework Version 3.
005     *
006     * Version: MPL 1.1
007     *
008     * The contents of this file are subject to the Mozilla Public License Version
009     * 1.1 (the "License"); you may not use this file except in compliance with
010     * the License. You may obtain a copy of the License at
011     * http://www.mozilla.org/MPL/
012     *
013     * Software distributed under the License is distributed on an "AS IS" basis,
014     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
015     * for the specific language governing rights and limitations under the
016     * License.
017     */
018    
019    package echopoint.google.chart;
020    
021    import echopoint.google.chart.internal.SimpleChart;
022    
023    import java.util.Collection;
024    
025    /**
026     * Component wrapper for a
027     * <a href='http://code.google.com/apis/chart/#pie_charts'>Pie chart</a>
028     * provided by <a href='http://code.google.com/apis/chart/'>Google Chart
029     * API</a>.
030     *
031     * <p>The following code shows sample use of this component:</p>
032     * <pre>
033     *   import echopoint.google.chart.PieChart;
034     *   import echopoint.google.chart.model.ChartData;
035     *
036     *     ...
037     *     final ChartData&lt;Integer&gt; data = new ChartData&lt;Integer&gt;();
038     *     final Integer[] array = new Integer[]
039     *        { 31, 28, 31, 30, 31, 31, 31, 31, 30, 31, 30, 31 };
040     *     data.setXdata( Arrays.asList( array ) );
041     *
042     *     final PieChart&lt;Integer&gt; chart = new PieChart&lt;Integer&gt;();
043     *     chart.setDimensions( PieChart.Dimensions.p3 );
044     *     final ArrayList&lt;ChartData&lt;Integer&gt;&gt; collection = new ArrayList&lt;ChartData&lt;Integer&gt;&gt;();
045     *     collection.add( data );
046     *     chart.setData( collection );
047     * </pre>
048     *
049     * @author Rakesh Vidyadharan 2008-08-21
050     * @version $Id: PieChart.java 83 2008-11-08 19:32:18Z sptrakesh $
051     */
052    public class PieChart<N extends Number> extends SimpleChart<N>
053    {
054      private static final long serialVersionUID = 1l;
055    
056      /** An enumeration used to represent the pie chart dimensions. */
057      public enum Dimensions { p, p3 }
058    
059      /**
060       * The property used to configure 2 or 3-dimensional charts.  This
061       * property is best styled.  Defaults to 2-d.
062       */
063      public static final String PROPERTY_DIMENSIONS = "dimensions";
064    
065      /**
066       * The property that holds the collection of string labels to associate with
067       * the segments in the pie chart.  Please see
068       * <a href='http://code.google.com/apis/chart/#pie_labels'>Pie Labels</a>
069       * notes regarding size requirements when using labels.
070       */
071      public static final String PROPERTY_LABELS = "labels";
072    
073      /**
074       * Return the {@link #PROPERTY_DIMENSIONS} property value.
075       *
076       * @return The value that indicates the chart dimensions.
077       */
078      public Dimensions getDimensions()
079      {
080        return (Dimensions) get( PROPERTY_DIMENSIONS );
081      }
082    
083      /**
084       * Set the value of the {@link #PROPERTY_DIMENSIONS} property.
085       *
086       * @param dimension The value to set.
087       */
088      public void setDimensions( final Dimensions dimension )
089      {
090        set( PROPERTY_DIMENSIONS, dimension );
091      }
092    
093      /**
094       * Return the {@link #PROPERTY_LABELS} property value.
095       *
096       * @return The labels value encoded as required by the chart api.
097       */
098      @SuppressWarnings( {"unchecked"} )
099      public Collection<String> getLabels()
100      {
101        return (Collection<String>) get( PROPERTY_LABELS );
102      }
103    
104      /**
105       * Set the value of the {@link #PROPERTY_LABELS} property.
106       *
107       * @param labels The value to set.
108       */
109      public void setLabels( final Collection<String> labels )
110      {
111        set( PROPERTY_LABELS, labels );
112      }
113    }