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.AdvancedChart;
022    import echopoint.google.chart.model.BarChartSize;
023    
024    /**
025     * Component wrapper for a
026     * <a href='http://code.google.com/apis/chart/#bar_charts'>Bar chart</a>
027     * provided by <a href='http://code.google.com/apis/chart/'>Google Chart
028     * API</a>.
029     *
030     * <p>The following code shows sample use of this component:</p>
031     * <pre>
032     *   import echopoint.google.chart.BarChart;
033     *   import echopoint.google.chart.model.ChartData;
034     *
035     *     ...
036     *     final ChartData&lt;Integer&gt; data = new ChartData&lt;Integer&gt;();
037     *     final Integer[] array = new Integer[] { 30,60,70,90,95,110 };
038     *     final List&lt;Integer&gt; xdata = Arrays.asList( array );
039     *     final int xmax = 120;
040     *
041     *     data.setXdata( xdata );
042     *     data.setXmax( xmax );
043     *
044     *     final BarChart&lt;Integer&gt; chart = new BarChart&lt;Integer&gt;();
045     *     chart.setOrientation( BarChart.Orientation.bhg );
046     *     final ArrayList&lt;ChartData&lt;Integer&gt;&gt; collection = new ArrayList&lt;ChartData&lt;Integer&gt;&gt;();
047     *     collection.add( data );
048     *     chart.setData( collection );
049     * </pre>
050     *
051     * @author Rakesh Vidyadharan 2008-08-20
052     * @version $Id: BarChart.java 83 2008-11-08 19:32:18Z sptrakesh $
053     */
054    public class BarChart<N extends Number> extends AdvancedChart<N>
055    {
056      private static final long serialVersionUID = 1l;
057    
058      /** Enumeration for orientation types supported by bar charts. */
059      public enum Orientation { bhs, bhg, bvs, bvg }
060    
061      /**
062       * The property that is used to specify the orientation type for the chart.
063       * This property may be styled.  Note that this property must be set
064       * before the chart can be configured.
065       */
066      public static final String PROPERTY_ORIENTATION = "orientation";
067    
068      /**
069       * The property used to configure the special bar chart width and size.
070       * This property is best styled.
071       */
072      public static final String PROPERTY_SIZE = "size";
073    
074      /**
075       * The property used to configure the zero line for the chart.  Note that
076       * the chart API supports achieving the same effect through the use of
077       * data scaling.  However, EchoPoint does not support this since we use
078       * only simple encoding and not text encoding for the data.  This property
079       * may be styled, however ever it may be easier to use dynamic setting based
080       * upon range of data.
081       */
082      public static final String PROPERTY_ZERO_LINE = "zeroLine";
083    
084      /**
085       * Return the value of the {@link #PROPERTY_ORIENTATION} property.
086       *
087       * @return The property value.
088       */
089      public Orientation getOrientation()
090      {
091        return (Orientation) get( PROPERTY_ORIENTATION );
092      }
093    
094      /**
095       * Set the value of the {@link #PROPERTY_ORIENTATION} property.
096       *
097       * @param orientation The value of the property to set.
098       */
099      public void setOrientation( final Orientation orientation )
100      {
101        set( PROPERTY_ORIENTATION, orientation );
102      }
103    
104      /**
105       * Return the value of the {@link #PROPERTY_SIZE} property.
106       *
107       * @return The property value.
108       */
109      public String getSize()
110      {
111        return (String) get( PROPERTY_SIZE );
112      }
113    
114      /**
115       * Set the value of the {@link #PROPERTY_SIZE} property.  This property
116       * is best styled.
117       *
118       * @param size The value to set.
119       */
120      public void setSize( final String size )
121      {
122        set( PROPERTY_SIZE, size );
123      }
124    
125      /**
126       * Set the value of the {@link #PROPERTY_SIZE} property using the model
127       * object that encapsulates bar chart size.
128       *
129       * @see #setSize( String )
130       * @param size The value to set.
131       */
132      public void setSize( final BarChartSize size )
133      {
134        setSize( size.toString() );
135      }
136    
137      /**
138       * Return the value of the {@link #PROPERTY_ZERO_LINE} property.
139       *
140       * @return The property value.
141       */
142      public String getZeroLine()
143      {
144        return (String) get( PROPERTY_ZERO_LINE );
145      }
146    
147      /**
148       * Set the value of the {@link #PROPERTY_ZERO_LINE} property.  This property
149       * may be styled.
150       *
151       * @param zeroLine The value to set.
152       */
153      public void setZeroLine( final String zeroLine )
154      {
155        set( PROPERTY_ZERO_LINE, zeroLine );
156      }
157    
158      /**
159       * Set the value of the {@link #PROPERTY_ZERO_LINE} property.  This property
160       * may be styled.
161       *
162       * @param zeroLine The value to set.
163       */
164      public void setZeroLine( final double zeroLine )
165      {
166        setZeroLine( String.valueOf( zeroLine ) );
167      }
168    }