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