public final class

ChartEngine

com.artfulbits.aiCharts.Base.ChartEngine

Class Overview

Represents Chart engine initially wrapped by ChartView class. Chart engine class is a top building block of aiCharts. Yet another way to initialize the chart is XML data inflation.
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.View.ChartView
     	android:id="@+id/chart"
     	<b>chart="@xml/chart"</b>
         android:layout_width="fill_parent"
     	android:layout_height="fill_parent"/>
 </LinearLayout>
 
chart.xml:
 <?xml version="1.0" encoding="UTF-8"?>
 <aiChart:chart
 	xmlns:aiChart="http://www.artfulbits.com/android/aiCharts">
 	<aiChart:area>
 		<aiChart:series
 			name="series1"
 			type="Line"
 			lineWidth="3" />
 	</aiChart:area>
 </aiChart:chart>
 
Activity.onCreate(Bundle):
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 // Retrieving ChartView from layout.
 ChartView chartView = (ChartView)findViewById(R.id.chart);
 // Retrieving inflated series.
 ChartSeries series = chartView.getSeries().get("series1");
 // Filling series with data.
 for (int i = 0; i < 10; i++)
 {
 	series.getPoints().addXY(i, Math.cos(i));
 }
 
Following output is expected:

XML Attributes
palette Defines palette
spacing Defines spacing between chart elements

See Also

Summary

Fields
public static final LicenseData LICENSE Get License Information which used by aiCharts library.
Public Constructors
ChartEngine()
Initializes a new instance of Chart.
ChartEngine(Resources res, int xmlId)
Initializes a new instance of ChartEngine.
ChartEngine(Resources res, XmlPullParser parser)
Initializes a new instance of ChartEngine.
Public Methods
void addInvalidateListener(IInvalidateListener listener)
Adds the invalidate listener that implements IInvalidateListener interface.
void draw(Canvas canvas)
Paints chart to canvas.
void ensureLayout(boolean force)
Update charts layout
ChartCollection<ChartAnnotation> getAnnotations()
Gets the annotations collection.
boolean getAntiAlias()
Gets value indicating that chart is drawn anti-aliased.
ChartNamedCollection<ChartArea> getAreas()
Gets the area collection.
boolean getAutoAlignAreas()
Gets value indicating whether chart should align child areas.
Rect getBounds()
Gets the chart bounds.
ChartNamedCollection<ChartLegend> getLegends()
Gets the legend collection.
ChartPalette getPalette()
Returns current palette assigned to chart.
ChartNamedCollection<ChartSeries> getSeries()
Gets the collection containing series of chart.
ChartSeriesStyle getSeriesStyle()
Returns general series style
int getSpacing()
Gets value indicating distance between chart and its elements.
ChartCollection<ChartTitle> getTitles()
Gets the title 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.
void removeInvalidateListener(IInvalidateListener listener)
Removes previously added invalidate listener.
void save(OutputStream stream)
Saves chart image to specified stream.
void save(Bitmap bitmap, boolean fitToBitmap)
Saves chart to specified Bitmap
void setAntiAlias(boolean antiAlias)
Sets value indicating that chart is drawn anti-aliased.
void setAutoAlignAreas(boolean autoAlignAreas)
Sets value indicating whether chart should align its areas.
void setBounds(int left, int top, int right, int bottom)
Sets the chart bounds.
void setBounds(int width, int height)
Sets the chart bounds
void setBounds(Rect bounds)
Sets the chart bounds.
void setHitTestEnabled(boolean enable)
Sets value indicating whether hit testing is enabled.
void setPalette(ChartPalette palette)
Sets chart palette.
void setSeriesStyle(ChartSeriesStyle style)
Sets general style for series.
void setSpacing(int spacing)
Sets value indicating distance between chart and its elements.

Fields

public static final LicenseData LICENSE

Get License Information which used by aiCharts library.

Public Constructors

public ChartEngine ()

Initializes a new instance of Chart. Instantiates areas, series, legend and titles collections. Initially, instance of Chart class is created by parent ChartView.

See Also

public ChartEngine (Resources res, int xmlId)

Initializes a new instance of ChartEngine. Inflates xml properties from specified resources by passed id.

Parameters
res instance of Resources containing XML to inflate.
xmlId resource ID.

public ChartEngine (Resources res, XmlPullParser parser)

Initializes a new instance of ChartEngine. Inflates xml properties from specified resources using specified parser.

Parameters
res instance of Resources containing XML to inflate.
parser instance of XmlPullParser that is used to parse specified resource.

Public Methods

public void addInvalidateListener (IInvalidateListener listener)

Adds the invalidate listener that implements IInvalidateListener interface. Target onInvalidate() is called when invalidation process was triggered.

 chart.addInvalidateListener(new IInvalidateListener()
 {
 
 	public void onInvalidate()
 	{
 		// Desired actions to respond chart invalidation.
 	}
 });
 

Parameters
listener instance of IInvalidateListener.

public void draw (Canvas canvas)

Paints chart to canvas. Generally, invoked via the recursive draw call from parent ChartView. However, this method could be used to draw chart on optionally supplied Canvas.

 Bitmap b = Bitmap.createBitmap(source);
 Canvas canvas = new Canvas(b);
 chart.draw(canvas);
 

Parameters
canvas instance of Canvas class.

public void ensureLayout (boolean force)

Update charts layout

Parameters
force - update even there wasn't any changes.

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 boolean getAntiAlias ()

Gets value indicating that chart is drawn anti-aliased.

Returns
  • true if chart is drawn anti-aliased, otherwise false.

public ChartNamedCollection<ChartArea> getAreas ()

Gets the area collection.

Returns
  • Instance of chart area collection.
See Also

public boolean getAutoAlignAreas ()

Gets value indicating whether chart should align child areas. Value is true by default.

Returns
  • true if chart will align its areas, otherwise false.
See Also

public Rect getBounds ()

Gets the chart bounds.

Returns
  • Rect representing chart bounds.

public ChartNamedCollection<ChartLegend> getLegends ()

Gets the legend collection.

Returns
  • instance of legend collection.

public ChartPalette getPalette ()

Returns current palette assigned to chart.

Returns
See Also

public ChartNamedCollection<ChartSeries> getSeries ()

Gets the collection containing series of chart.

Returns
See Also

public ChartSeriesStyle getSeriesStyle ()

Returns general series style

Returns
  • style

public int getSpacing ()

Gets value indicating distance between chart and its elements.

Returns
  • spacing distance between chart elements.
See Also

public ChartCollection<ChartTitle> getTitles ()

Gets the title collection.

Returns
  • instance of title collection.
See Also

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.
objects - List to fill with charts objects that exist beneath specified point.

public boolean isHitTestEnabled ()

Gets value indicating whether hit testing is enabled.

Returns
  • true, if ChartEngine tracks its children for further hit testing.

public void removeInvalidateListener (IInvalidateListener listener)

Removes previously added invalidate listener.

Parameters
listener instance of previously added IInvalidateListener descendant.

public void save (OutputStream stream)

Saves chart image to specified stream. Compress format - PNG.

Parameters
stream stream to save the chart.

public void save (Bitmap bitmap, boolean fitToBitmap)

Saves chart to specified Bitmap

Parameters
bitmap a bitmap to save
fitToBitmap indicates whether chart should be fitted to bitmap size.

public void setAntiAlias (boolean antiAlias)

Sets value indicating that chart is drawn anti-aliased.
If AntiAlias is set to true, the chart might work slowly, should you experience performance issues, set this property to false.

Parameters
antiAlias true if chart is to be drawn anti-aliased, otherwise false.

public void setAutoAlignAreas (boolean autoAlignAreas)

Sets value indicating whether chart should align its areas.

Parameters
autoAlignAreas true if chart will align its areas, otherwise false
See Also

public void setBounds (int left, int top, int right, int bottom)

Sets the chart bounds.

Parameters
left The X coordinate of the left side of the rectangle
top The Y coordinate of the top of the rectangle
right The X coordinate of the right side of the rectangle
bottom The Y coordinate of the bottom of the rectangle

public void setBounds (int width, int height)

Sets the chart bounds

Parameters
width desired width of chart.
height bounds height of chart.

public void setBounds (Rect bounds)

Sets the chart bounds.

Parameters
bounds Rect representing chart bounds.

public void setHitTestEnabled (boolean enable)

Sets value indicating whether hit testing is enabled.

Parameters
enable true, if ChartEngine should track its children for further hit testing, otherwise false.

public void setPalette (ChartPalette palette)

Sets chart palette.

Parameters
palette instance of ChartPalette class.

public void setSeriesStyle (ChartSeriesStyle style)

Sets general style for series.

Parameters
style instance of series style

public void setSpacing (int spacing)

Sets value indicating distance between chart and its elements.

Parameters
spacing distance between chart elements.