Quick Start Guide

Draw a Simple Chart

Start by creating a new Android Application project:

  1. From the Welcome screen click New Project (if you have a project already open click File > New > New Project…)
  2. Give the application an Application name: ShinobiChartsQuickStart and a suitable Package name (we use com.example.shinobichartsquickstart but you should use your own)
  3. Choose a suitable location for the project and click Next
  4. Click Next again to choose the default form factor (Phone and Tablet) and Minimum SDK (shinobicharts supports down to Android API 14 so we’ll use this)
  5. Click Empty Activity and click Next
  6. Choose an appropriate name for your activity - this guide will assume the main activity is named ShinobiQuickStartActivity
  7. Click Finish and your project will be created

Now that you have your new project set up follow the Android Studio import instructions to add a dependency to the shinobicharts library from your application. If you are using Eclipse then you can follow the Eclipse import instructions.

Add the ShinobiChart

In the XML layout file for your Activity (named activity_shinobi_quick_start.xml), which can be found in the res/layout/ folder, click on the tab along the bottom called Text to show the raw XML. Replace the TextView with a SupportChartFragment:

    android:layout_height="match_parent" />

Here the SupportChartFragment is being told to match the dimensions of its parent and is being given an id which makes it easier to retrieve in code.

Now open up ShinobiQuickStartActivity.java. You’ll see Android Studio has already added some code to your Activity. You only want to set up your chart the first time the Activity is created so add the following to the end of the onCreate() method:

if (savedInstanceState == null) {


In Android, configuration changes such as rotating your device cause Activities to be destroyed and re-created. You can tell if the Activity is being created for the first time by checking to see if savedInstanceState == null. Normally Fragments within an Activity will be destroyed and re-created as well. However, by default, a SupportChartFragment is retained across Activity re-creation so you only need to do the setup once.

Add the following inside the if statement you just added:

SupportChartFragment chartFragment =
                (SupportChartFragment) getFragmentManager().findFragmentById(R.id.chart);

ShinobiChart shinobiChart = chartFragment.getShinobiChart();
shinobiChart.setTitle("My First Chart");

Using the id you gave the SupportChartFragment in the XML, and the Activity’s FragmentManager, you can get a reference to it in code. From the SupportChartFragment you obtain the ShinobiChart and give it a title.

Tip: You can use the Alt+Enter keyboard shortcut in Android Studio to add the necessary import statements.

If you have downloaded a trial version of shinobicharts you will have been issued with a trial key. You will need to give this key to the chart in order for it to be displayed. You can do this as follows:


Make sure you change <trial_key_here> to the trial key you were given!

The main parts of a chart can be configured via some key properties on the ShinobiChart object. For example, you’ll need to add the axes and series. In this example, you’re making a chart with three columns on linear numeric scales. For now, add the axes and we’ll come back to the series a little bit later. Still inside the if statement add:

NumberAxis xAxis = new NumberAxis();

NumberAxis yAxis = new NumberAxis();

Here you’re creating both the X axis and Y axis as a NumberAxis and then setting them on the chart.

So with the exception of the data, the chart is set up.

<< Previous: Introduction | Next: Adding a Series >>