com.jjoe64.graphview
Class GraphView

java.lang.Object
  extended by LinearLayout
      extended by com.jjoe64.graphview.GraphView
Direct Known Subclasses:
BarGraphView, LineGraphView

public abstract class GraphView
extends LinearLayout

GraphView is a Android View for creating zoomable and scrollable graphs. This is the abstract base class for all graphs. Extend this class and implement #drawSeries(Canvas, GraphViewDataInterface[], float, float, float, double, double, double, double, float) to display a custom graph. Use LineGraphView for creating a line chart.

Author:
jjoe64 - jonas gehring - http://www.jjoe64.com Copyright (C) 2011 Jonas Gehring Licensed under the GNU Lesser General Public License (LGPL) http://www.gnu.org/licenses/lgpl.html

Nested Class Summary
static class GraphView.GraphViewData
          one data set for a graph series
static class GraphView.LegendAlign
           
 
Field Summary
protected  Paint paint
           
 
Constructor Summary
GraphView(Context context, AttributeSet attrs)
           
GraphView(Context context, java.lang.String title)
           
 
Method Summary
 void addSeries(GraphViewSeries series)
          add a series of data to the graph
protected  void drawLegend(Canvas canvas, float height, float width)
           
protected abstract  void drawSeries(Canvas canvas, GraphViewDataInterface[] values, float graphwidth, float graphheight, float border, double minX, double minY, double diffX, double diffY, float horstart, GraphViewSeries.GraphViewSeriesStyle style)
           
protected  java.lang.String formatLabel(double value, boolean isValueX)
          Deprecated. use setCustomLabelFormatter(CustomLabelFormatter)
 CustomLabelFormatter getCustomLabelFormatter()
           
 GraphViewStyle getGraphViewStyle()
           
 GraphView.LegendAlign getLegendAlign()
          get the position of the legend
 float getLegendWidth()
           
protected  double getMaxX(boolean ignoreViewport)
          returns the maximal X value of the current viewport (if viewport is set) otherwise maximal X value of all data.
protected  double getMaxY()
          returns the maximal Y value of all data.
protected  double getMinX(boolean ignoreViewport)
          returns the minimal X value of the current viewport (if viewport is set) otherwise minimal X value of all data.
protected  double getMinY()
          returns the minimal Y value of all data.
 boolean isDisableTouch()
           
 boolean isScrollable()
           
 boolean isShowLegend()
           
 void redrawAll()
          forces graphview to invalide all views and caches.
 void removeAllSeries()
          removes all series
 void removeSeries(GraphViewSeries series)
          removes a series
 void removeSeries(int index)
          removes series
 void scrollToEnd()
          scrolls to the last x-value
 void setCustomLabelFormatter(CustomLabelFormatter customLabelFormatter)
          set a custom label formatter
 void setDisableTouch(boolean disableTouch)
          The user can disable any touch gestures, this is useful if you are using a real time graph, but don't want the user to interact
 void setGraphViewStyle(GraphViewStyle style)
          set custom graphview style
 void setHorizontalLabels(java.lang.String[] horlabels)
          set's static horizontal labels (from left to right)
 void setLegendAlign(GraphView.LegendAlign legendAlign)
          legend position
 void setLegendWidth(float legendWidth)
          legend width
 void setManualYAxis(boolean manualYAxis)
          you have to set the bounds setManualYAxisBounds(double, double).
 void setManualYAxisBounds(double max, double min)
          set manual Y axis limit
 void setScalable(boolean scalable)
          this forces scrollable = true
 void setScrollable(boolean scrollable)
          the user can scroll (horizontal) the graph.
 void setShowLegend(boolean showLegend)
           
 void setTitle(java.lang.String title)
          sets the title of graphview
 void setVerticalLabels(java.lang.String[] verlabels)
          set's static vertical labels (from top to bottom)
 void setViewPort(double start, double size)
          set's the viewport for the graph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

paint

protected final Paint paint
Constructor Detail

GraphView

public GraphView(Context context,
                 AttributeSet attrs)

GraphView

public GraphView(Context context,
                 java.lang.String title)
Parameters:
context -
title - [optional]
Method Detail

addSeries

public void addSeries(GraphViewSeries series)
add a series of data to the graph

Parameters:
series -

drawLegend

protected void drawLegend(Canvas canvas,
                          float height,
                          float width)

drawSeries

protected abstract void drawSeries(Canvas canvas,
                                   GraphViewDataInterface[] values,
                                   float graphwidth,
                                   float graphheight,
                                   float border,
                                   double minX,
                                   double minY,
                                   double diffX,
                                   double diffY,
                                   float horstart,
                                   GraphViewSeries.GraphViewSeriesStyle style)

formatLabel

@Deprecated
protected java.lang.String formatLabel(double value,
                                                  boolean isValueX)
Deprecated. use setCustomLabelFormatter(CustomLabelFormatter)

formats the label use #setCustomLabelFormatter or static labels if you want custom labels

Parameters:
value - x and y values
isValueX - if false, value y wants to be formatted
Returns:
value to display

getCustomLabelFormatter

public CustomLabelFormatter getCustomLabelFormatter()
Returns:
the custom label formatter, if there is one. otherwise null

getGraphViewStyle

public GraphViewStyle getGraphViewStyle()
Returns:
the graphview style. it will never be null.

getLegendAlign

public GraphView.LegendAlign getLegendAlign()
get the position of the legend

Returns:

getLegendWidth

public float getLegendWidth()
Returns:
legend width

getMaxX

protected double getMaxX(boolean ignoreViewport)
returns the maximal X value of the current viewport (if viewport is set) otherwise maximal X value of all data.

Parameters:
ignoreViewport - warning: only override this, if you really know want you're doing!

getMaxY

protected double getMaxY()
returns the maximal Y value of all data. warning: only override this, if you really know want you're doing!


getMinX

protected double getMinX(boolean ignoreViewport)
returns the minimal X value of the current viewport (if viewport is set) otherwise minimal X value of all data.

Parameters:
ignoreViewport - warning: only override this, if you really know want you're doing!

getMinY

protected double getMinY()
returns the minimal Y value of all data. warning: only override this, if you really know want you're doing!


isDisableTouch

public boolean isDisableTouch()

isScrollable

public boolean isScrollable()

isShowLegend

public boolean isShowLegend()

redrawAll

public void redrawAll()
forces graphview to invalide all views and caches. Normally there is no need to call this manually.


removeAllSeries

public void removeAllSeries()
removes all series


removeSeries

public void removeSeries(GraphViewSeries series)
removes a series

Parameters:
series - series to remove

removeSeries

public void removeSeries(int index)
removes series

Parameters:
index -

scrollToEnd

public void scrollToEnd()
scrolls to the last x-value

Throws:
java.lang.IllegalStateException - if scrollable == false

setCustomLabelFormatter

public void setCustomLabelFormatter(CustomLabelFormatter customLabelFormatter)
set a custom label formatter

Parameters:
customLabelFormatter -

setDisableTouch

public void setDisableTouch(boolean disableTouch)
The user can disable any touch gestures, this is useful if you are using a real time graph, but don't want the user to interact

Parameters:
disableTouch -

setGraphViewStyle

public void setGraphViewStyle(GraphViewStyle style)
set custom graphview style

Parameters:
style -

setHorizontalLabels

public void setHorizontalLabels(java.lang.String[] horlabels)
set's static horizontal labels (from left to right)

Parameters:
horlabels - if null, labels were generated automatically

setLegendAlign

public void setLegendAlign(GraphView.LegendAlign legendAlign)
legend position

Parameters:
legendAlign -

setLegendWidth

public void setLegendWidth(float legendWidth)
legend width

Parameters:
legendWidth -

setManualYAxis

public void setManualYAxis(boolean manualYAxis)
you have to set the bounds setManualYAxisBounds(double, double). That automatically enables manualYAxis-flag. if you want to disable the menual y axis, call this method with false.

Parameters:
manualYAxis -

setManualYAxisBounds

public void setManualYAxisBounds(double max,
                                 double min)
set manual Y axis limit

Parameters:
max -
min -

setScalable

public void setScalable(boolean scalable)
this forces scrollable = true

Parameters:
scalable -

setScrollable

public void setScrollable(boolean scrollable)
the user can scroll (horizontal) the graph. This is only useful if you use a viewport setViewPort(double, double) which doesn't displays all data.

Parameters:
scrollable -

setShowLegend

public void setShowLegend(boolean showLegend)

setTitle

public void setTitle(java.lang.String title)
sets the title of graphview

Parameters:
title -

setVerticalLabels

public void setVerticalLabels(java.lang.String[] verlabels)
set's static vertical labels (from top to bottom)

Parameters:
verlabels - if null, labels were generated automatically

setViewPort

public void setViewPort(double start,
                        double size)
set's the viewport for the graph.

Parameters:
start - x-value
size -
See Also:
to limit the y-viewport