public class

ChartView

extends View
java.lang.Object
   ↳ android.view.View
     ↳ com.artfulbits.aiCharts.ChartView

Class Overview

Represents View-derived class used to draw chart. ChartView initially wraps ChartEngine objects and forwards layout and draw calls accordingly. All operations involving chart's objects manipulation have to be performed on wrapped ChartEngine. ChartView class could be instantiated directly in hosting activity or inflated along with the rest layout tree tree during regular call to Activity.setContentView().
Following snippet demonstrates instantiation the view from Activity.onCreate(Bundle) method.
Consider following layout defined in Android layout resources:

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/mainLayout"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 </LinearLayout>
 
In Activity.onCreate(Bundle) ChartView is added to main layout:
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 // Retrieving main layout.
 LinearLayout mainLayout = (LinearLayout)findViewById(R.id.mainLayout);
 // Instantiating chart view.
 ChartView chartView = new ChartView(this);
 // Retrieving default ChartSeries
 ChartSeries defaultSeries = chartView.initDefaultChart();
 // Caching points collection.
 ChartPointCollection points = defaultSeries.getPoints();
 // Adding 10 points to series.
 for (int i = 0; i < 10; i++)
 {
 	points.addXY(i, i * 100);
 }
 // Adding chart view to main view.
 mainLayout.addView(chartView);
 
Following output is expected:

Identical behavior could be achieved by having Android framework inflate aiCharts instead:
Main.xml:
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="vertical"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">
 		 <com.artfulbits.aiCharts.ChartView
         android:id="@+id/chartView"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"/> 
 </LinearLayout>
 
Activity.onCreate(Bundle)
 ...
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 ChartView chartView = (ChartView)findViewById(R.id.chartView);
 ...
 
Samples along the SDK will give more idea of ChartView class usages.

See Also

Summary

Constants
int PANNING_BOTH Both: the horizontal and vertical panning.
int PANNING_HORIZONTAL Horizontal panning.
int PANNING_NONE No panning.
int PANNING_VERTICAL Vertical panning.
[Expand]
Inherited Constants
From class android.view.View
Public Constructors
ChartView(Context context)
Initializes a new instance of ChartView with Context context specified.
ChartView(Context context, int chartId)
Initializes a new instance of ChartView with context specified.
ChartView(Context context, AttributeSet attributes)
Initializes a new instance of ChartView with context and AttributeSet attributes specified.
ChartView(Context context, AttributeSet attributes, int defStyle)
Initializes a new instance of ChartView with context, attributes and style specified.
Public Methods
void fling(ChartArea area, ChartAxis xAxis, ChartAxis yAxis, float xVelocity, float yVelocity)
Starts fling animation for specified area.
void fling(ChartArea area, float xVelocity, float yVelocity)
Starts fling animation for specified area.
ChartCollection<ChartAnnotation> getAnnotations()
Gets the annotations collection.
ChartNamedCollection<ChartArea> getAreas()
Gets current areas collection linked to wrapped chart.
ChartEngine getChart()
Gets the instance of ChartEngine class that is currently wrapped by this view.
GestureDetector getGestureDetector()
Gets gesture detector to handle touch events.
ChartNamedCollection<ChartLegend> getLegends()
Gets the legend collection.
ChartPalette getPalette()
Gets the palette that is currently user for series of chart.
ChartNamedCollection<ChartSeries> getSeries()
Gets the series collection.
ChartSeriesStyle getSeriesStyle()
Returns general series style
ChartCollection<ChartTitle> getTitles()
Returns titles collection.
List<Object> hitTest(int x, int y)
This method is deprecated. hitTest(int, int, List)
void hitTest(int x, int y, List<Object> objects)
Retrieves all chart's objects that exist at specified coordinate.
boolean isHitTestEnabled()
Gets value indicating whether hit testing is enabled.
boolean onTouchEvent(MotionEvent event)
void scroll(ChartArea area, ChartAxis xAxis, ChartAxis yAxis, float xScroll, float yScroll)
Scrolls specified axes.
void scroll(ChartArea area, float xScroll, float yScroll)
Scrolls default axes of specified area.
void setChart(ChartEngine chart)
Sets the instance of chart engine class.
void setChart(int resId)
Set the instance of chart engine based on XML template file stored in application resources.
void setGestureDetector(GestureDetector gestureDetector)
Sets gesture detector to handle touch events.
void setGestureDetector(GestureDetector.OnGestureListener gestureListener)
Sets gesture listener to handle touch events.
void setHitTestEnabled(boolean enable)
Controls hit testing tracks for series.
void setPalette(ChartPalette palette)
Sets the palette that is currently user for series of chart.
void setPanning(int orientation)
This method is deprecated. Please use setGestureDetector(GestureDetector) and ChartGestureListener
void setSeriesStyle(ChartSeriesStyle style)
Sets general style for series.
void stopFling()
Stops all scrolling animations
void stopFling(ChartArea area)
Stops scrolling animation for specified area
[Expand]
Inherited Methods
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Constants

public static final int PANNING_BOTH

Both: the horizontal and vertical panning.

Constant Value: 7 (0x00000007)

public static final int PANNING_HORIZONTAL

Horizontal panning.

Constant Value: 6 (0x00000006)

public static final int PANNING_NONE

No panning.

Constant Value: 0 (0x00000000)

public static final int PANNING_VERTICAL

Vertical panning.

Constant Value: 5 (0x00000005)

Public Constructors

public ChartView (Context context)

Initializes a new instance of ChartView with Context context specified.

Parameters
context instance of Context informational class.

public ChartView (Context context, int chartId)

Initializes a new instance of ChartView with context specified.

Parameters
context instance of Context informational class.
chartId The identifier of the chart xml resource.

public ChartView (Context context, AttributeSet attributes)

Initializes a new instance of ChartView with context and AttributeSet attributes specified.

Parameters
context instance of Context informational class.
attributes instance of XML AttributeSet attributes.

public ChartView (Context context, AttributeSet attributes, int defStyle)

Initializes a new instance of ChartView with context, attributes and style specified.

Parameters
context instance of Context informational class.
attributes instance of XML attributes.
defStyle the default style to apply to this view.

Public Methods

public void fling (ChartArea area, ChartAxis xAxis, ChartAxis yAxis, float xVelocity, float yVelocity)

Starts fling animation for specified area.

Parameters
area - ChartArea instance
xAxis - ChartAxis for X scrolling
yAxis - ChartAxis for Y scrolling
xVelocity - velocity of scrolling for X Axis in pixels per second
yVelocity - velocity of scrolling for Y Axis in pixels per second

public void fling (ChartArea area, float xVelocity, float yVelocity)

Starts fling animation for specified area.

Parameters
area - ChartArea instance
xVelocity - velocity of scrolling for X Axis in pixels per second
yVelocity - velocity of scrolling for Y Axis in pixels per second

public ChartCollection<ChartAnnotation> getAnnotations ()

Gets the annotations collection. Annotation should be added to this collection in order to be rendered on chart's surface.

Returns

public ChartNamedCollection<ChartArea> getAreas ()

Gets current areas collection linked to wrapped chart.

Returns
See Also
  • ChartView#addArea()

public ChartEngine getChart ()

Gets the instance of ChartEngine class that is currently wrapped by this view.

Returns

public GestureDetector getGestureDetector ()

Gets gesture detector to handle touch events.

Returns

public ChartNamedCollection<ChartLegend> getLegends ()

Gets the legend collection.

Returns

public ChartPalette getPalette ()

Gets the palette that is currently user for series of chart.

Returns
See Also

public ChartNamedCollection<ChartSeries> getSeries ()

Gets the series collection.

 // Iterate over series collection.
 for(ChartSeries series : chartView.getSeries())
 {
 	// Set series properties here
 	...
 }
 

Returns

public ChartSeriesStyle getSeriesStyle ()

Returns general series style

Returns
  • style

public ChartCollection<ChartTitle> getTitles ()

Returns titles collection.

Returns

public List<Object> hitTest (int x, int y)

This method is deprecated.
hitTest(int, int, List)

Retrieves all chart's objects that exist at specified coordinate.

Parameters
x X coordinate of target point.
y Y coordinate of target point.
Returns
  • List filled with charts objects that exist beneath specified point.

public void hitTest (int x, int y, List<Object> objects)

Retrieves all chart's objects that exist at specified coordinate.

Parameters
x X coordinate of target point.
y Y coordinate of target point.
Returns
  • List filled with charts objects that exist beneath specified point.

public boolean isHitTestEnabled ()

Gets value indicating whether hit testing is enabled.

Returns
  • true if hit testing is enabled, otherwise false.

public boolean onTouchEvent (MotionEvent event)

Since: API Level

public void scroll (ChartArea area, ChartAxis xAxis, ChartAxis yAxis, float xScroll, float yScroll)

Scrolls specified axes.

Parameters
area - ChartArea instance
xAxis - ChartAxis for X scrolling
yAxis - ChartAxis for Y scrolling
xScroll - scroll offset for X Axis in pixels
yScroll - scroll offset for Y Axis in pixels

public void scroll (ChartArea area, float xScroll, float yScroll)

Scrolls default axes of specified area.

Parameters
area - ChartArea instance
xScroll - scroll offset for X Axis in pixels
yScroll - scroll offset for Y Axis in pixels

public void setChart (ChartEngine chart)

Sets the instance of chart engine class. It will be used for charts painting.

Parameters
chart reference on chart engine instance.

public void setChart (int resId)

Set the instance of chart engine based on XML template file stored in application resources.

Parameters
resId application resource identifier valid for set in constructor context.

public void setGestureDetector (GestureDetector gestureDetector)

Sets gesture detector to handle touch events.

Parameters
gestureDetector GestureDetector instance.

public void setGestureDetector (GestureDetector.OnGestureListener gestureListener)

Sets gesture listener to handle touch events.

Parameters
gestureListener GestureDetector.OnGestureListener instance.

public void setHitTestEnabled (boolean enable)

Controls hit testing tracks for series.

Parameters
enable value that indicates whether chart has its hit testing enabled.

public void setPalette (ChartPalette palette)

Sets the palette that is currently user for series of chart.
For customization purposes, default series coloring can be replaced with a custom one:

 chartView.setPalette(new ChartPalette(Color.GREEN));
 
aiCharts has several predefined palettes:
 // Set the OpenOffice palette.
 chartView.setPalette(ChartPalette.OpenOffice);
 
 // Set the grayscale palette.
 chartView.setPalette(ChartPalette.Grayscale);
 

Parameters
palette instance of ChartPalette class that provides colors for series.

public void setPanning (int orientation)

This method is deprecated.
Please use setGestureDetector(GestureDetector) and ChartGestureListener

Sets panning value for chart view.

Parameters
orientation value of orientation.

public void setSeriesStyle (ChartSeriesStyle style)

Sets general style for series.

Parameters
style instance of series style

public void stopFling ()

Stops all scrolling animations

public void stopFling (ChartArea area)

Stops scrolling animation for specified area

Parameters
area - area instance