Java for BlackBerry Tutorial 1

From Steema Software Reference Wiki
Jump to: navigation, search

JavaBlackBerryHeaderLogo.png

Contents page
Next


Tutorial 1 - Getting started

Getting Started - building Charts and populating Data Series


Introduction

You may define the Chart appearance, titles, Legend characteristics and 3D aspect without having to include a data Series.
That gives you the freedom to add and remove different data Series types at runtime without having to redefine the whole Chart look and feel.

Pieces.png 

Everything comes together to make the final Chart, with Chart axes being the interface between Chart and Series.
A Series has data, and its values will influence the label characteristics of the Chart axes.
The axes appearance, colours, grid frequency and label fonts may all be defined for the Chart before adding data Series.
TeeChart will make a best estimate of most values to minimise the need for you to manually define Chart and Series methods.



The steps in this tutorial highlight how easy it is to build a Chart from scratch to enable you to modify and further enhance the appearance and functionality of the Chart at runtime. Good Charting !!

Building a Chart

Including TeeChart on the BlackBerry Page

Your BlackBerry project will contain Activities in which you will want to include a TeeChart. For example:

public final class Home extends MainScreen implements FieldChangeListener { ...

At some location in the code process you need to create the Chart. In the TeeChart demo it is created in the constructor of the class. Eg. (Your .java unit should include an import to 'com.steema.teechart.Chart').Then add the Chart to the screen.

/** * Creates a new StartScreen object

public Home() { // Set the displayed title of the screen setTitle("TeeChart Features"); createLayout();

chart = new TChart(); add(chart);

// Set Chart Settings ApplyChartSettings(); DoLineSeries(); }

Populate a new data Series

For programmed input of data you will need to write some code. This section will show you the steps necessary to build a chart with coded input.

 At runtime the Series will be empty of data unless you manually populate it. Create a button for the page and add the following code:

(Your .java unit should include an import to 'com.steema.teechart.styles.*').

Series bar = new Bar(chart.getChart());
chart.getAxes().getBottom().setIncrement(1);
bar.add(123, "Apples", Color.green);
bar.add(456, "Oranges", Color.red);
bar.add(321, "Kiwis", Color.yellow);
bar.add(78, "Bananas", Color.orange);

Run the project and press the button. Four new bars will appear on your Chart. That's it !! There's no more to it.

If you leave the colour variables out TeeChart will assign colours according to the selected Chart Theme Colour Palette.

e.g.

Series bar = new Bar(chart.getChart());
bar.add(123, "Apples");
bar.add(456, "Oranges");
bar.add(321, "Kiwis");
bar.add(78, "Bananas");

will give the following result:

BbChart.jpg

The basic Series' add method accepts 3 variables, Value, Label and Colour. The add method thus assumes equal spacing of values on the Label axis (in this case the X-Axis). Several add overloads are available according to the Series Type you are using. The Bar Series will accept x and y values.
Add another button to your project and put this code in it. Run the Project and add points using this code:

java.util.Random rnd = new java.util.Random();

Series bar = new Bar(chart.getChart());

if (bar.getCount() > 0)
{
// Increment X Axis value and add a new random point
	bar.add((bar.getXValues().getLast()   rnd.nextInt(10)),
		((bar.getYValues().getLast() / (bar.getYValues().getLast() - 1.0))
		rnd.nextInt(10)), "Lemons", Color.greenYellow);
}
else
{
	// Add a new random point
	bar.add(1, rnd.nextInt(10), "Lemons", Color.yellow);
}

Selecting a Series type to suit your needs

Series Type

No. of variables

Datasource Properties

Standard types

Line

2

XValues, YValues, XLabel

Horizontal Line

2

XValues, YValues, XLabel

Fast Line

2

XValues, YValues, XLabel

Bar

2

XValues, YValues (called Bar), XLabel

HorizBar

2

XValues, YValues (called Bar), XLabel

Area

2

XValues, YValues, XLabel

HorizArea

2

XValues, YValues, XLabel

Point

2

Xvalues, YValues, XLabel

Pie

1

PieValues, XLabel

Arrow

4

StartXValues, StartYValues, XLabel, EndXValues, EndYValues

Bubble

3

Xvalues, YValues, XLabel, RadiusValues

Gantt

3

StartValues, EndValues, AY (Y axis level), AXLabel (Label optionally shown on Y-axis or as mark)

Shape

4

X0 (Top), Y0 (Bottom), X1 (Left), Y1 (Right)

Subset of Extended Types

Bezier

2

XValues, YValues, XLabel

Candle

5

OpenValues, CloseValues, HighValues, LowValues, DateValues

Contour

3

XValues, YValues, XLabel, ZValues

Error Bar

3

XValues, YValues, XLabel, ErrorValues

Point3D

3

XValues, YValues, XLabel, ZValues

Polar

2

XValues, YValues, Labels (Polar has Angle and Radius)

Radar

2

XValues, YValues, Labels (Radar has Angle and Radius)

3D Surface

3

XValues, YValues, ZValues

Volume

2

XValues, YValues (VolumeValues), XLabel

Other Series types

There are many more TeeChart Series Types. Please check the definition of the Series type you wish to use, using either the programming environment's intellisense code prompt or the TeeChart Javadoc reference document.



Contents page

NEXT


© 1998-2014 Steema Software SL. All rights reserved.