Using TeeChart Java with Android Studio

Minimal example using TeeChart Java in Google’s Android Studio.

Android Studio home page:

https://developer.android.com/sdk/installing/studio.html

Download:

Download the example (9MB)

If you want to recreate this project, the steps are as follows:

1) TeeChart Java for Android

The above example download includes an evaluation version of TeeChart.Android.jar library. (The evaluation version draws a watermark)

If you wish to download the full version or the full evaluation with examples and tutorials, please follow this link:

http://steema.com/download/java

2) Create a new project in Android Studio (blank activity)

3) Copy TeeChart library to the app\libs folder

In your example project folders, copy the TeeChart.Android.jar file (from the above download zip)

….\app\libs\TeeChart.Android.jar

After some seconds, Android Studio will automatically recognize the new copied file and will appear under the libs tree node.

If it doesn’t, right click the libs node and click on “Synchronize libs” option.

4) At the main activity java, type this code:

The main java source file is at (for example):

C:\Android Studio\app\src\main\java\com\david\demo\MyActivity.java

import com.steema.teechart.TChart;
import com.steema.teechart.drawing.Color;
import com.steema.teechart.styles.*;
import com.steema.teechart.styles.Series;

...

protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(layout.activity_my);

  // Find the Layout:
  ViewGroup v;
  v = (ViewGroup) findViewById( id.mylayout );

  // Create a Chart and add it to Layout:
  TChart chart = new TChart( this );
  v.addView( chart );

  // Create a new series of data:
  Series series1 = new Pie( chart.getChart() ); // Bar,Area,Line etc

  // Add some sample data:
  
  series1.add( 123, "Apples", Color.green );
  series1.add( 456, "Oranges", Color.red );
  series1.add( 321, "Kiwis", Color.yellow );

  // Cosmetic options:
  chart.getAxes().getBottom().setIncrement( 1 );
  chart.getLegend().getFont().setSize(36); 
  series1.getMarks().getFont().setSize(36); 
  chart.getHeader().getFont().setSize(44); 
  chart.getPanel().getGradient().setVisible(true); 
} 

 

5) Run or debug

Clicking the ide Run or Debug buttons (or menu options) will execute the application.

A Pie chart appears with 3 slices at your Android device (phone or tablet), or at the emulator:

 

TeeChart Java for Android

 

 

 

 

New SeriesRegion tool for TeeChart Java

The majority of TeeChart versions already include a tool called SeriesRegion; the time for TeeChart Java to make a step forward has arrived!

To make this tool available you only have to include the according import:

import com.steema.teechart.tools.SeriesRegion;

Then, to use it you only need a chart and a series to link it:

Line line1 = new Line(chart1.getChart());
line1.fillSampleValues(20);

SeriesRegion seriesRegionTool1 = new SeriesRegion(chart1.getChart());
seriesRegionTool1.setSeries(line1);

Other properties this tool includes are AutoBound, UseOrigin, Origin, LowerBound, UpperBound and DrawBehindSeries. You can use the getters and setters to retrieve or set their values. Here a short description of their purpose:

  • AutoBound: If true, region left and right bounds are equal to series minimum and maximum x value.
  • Origin: Region bottom or upper limit. Used only if UseOrigin is true.
  • UseOrigin: If true, region bottom or upper limit is defined by Origin.
  • LowerBound: Defines region left (series not mandatory values) lower bound.
  • UpperBound: Defines region right (series not mandatory values) upper bound.
  • DrawBehindSeries: If true, draw region behind series. If false, draw region over series.

Also note you can access its Brush and Pen like with the other tools inheriting from Tool class.

Playing with this tool and its properties, you can get something like in the image below, extracted from the Features Demo:

SeriesRegion

This tool and the respective demos will be included with the next maintenance release of TeeChart Java (both Swing and SWT) and TeeChart Java for Android.