SWTChart

light weight chart component

Table of Contents


1. Getting started

1.1. Installation

Download an SWTChart archive file at SourceForge, unzip it, and find README.html which describes how to install.

1.2. How to show an empty chart

As a usual SWT widget, instantiate the class org.swt.Chart giving a composite control and a style of control.

new Chart(composite, SWT.NONE);

That's it. An empty chart will be shown as below.

1.3. How to show series

Next step is to show series on chart. Let's show the following double array as a line chart.

double[] ySeries = { 0.3, 1.4, 1.3, 1.9, 2.1 };

1. get a series set which is a container of series.

ISeriesSet seriesSet = chart.getSeriesSet();

2. create a series giving a series type and a series identifier.

This time, you will show a line chart, so the series type is SeriesType.LINE, while the identifier can be any string like "line series".

ISeries series = seriesSet.createSeries(SeriesType.LINE, "line series");

3. set the array for Y series.

series.setYSeries(ySeries);

Now, line series is shown on chart.

The range for X and Y axis is still 0 ~ 1. It should be adjusted so that series are fully shown.

4. get an axis set which is a container of axes.

IAxisSet axisSet = chart.getAxisSet();

5. adjust the range for all axes.

axisSet.adjustRange();

Finally, series are fully shown.

2. Concepts

2.1. Overview

As described in the class diagram below, Chart is composed of Legend, Title, Axis Set and Series Set. Axis Set and Series Set are a container of axes and series respectively. Axis is composed of Grid, Title and Axis Tick. Series has Series Label.

2.2. Chart

2.2.1. Plot Area

Plot Area is an area where series are drawn.

Since plot area is org.eclipse.swt.widgets.Composite, you can add key/mouse listeners or pop up menus on it.

Composite composite = chart.getPlotArea();
composite.addListener(SWT.MouseDown, new Listener() {
    public void handleEvent(Event event) {
        //
    }
});

2.2.2. Background

Background of chart is a background color except for legend and prot area. The background is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the background to light red.

Color color = new Color(Display.getDefault(), 255, 128, 128);
chart.setBackground(color);

2.2.3. Background in Plot Area

Background in Plot Area is a background color in plot area. The background is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the background in plot area to light red.

Color color = new Color(Display.getDefault(), 255, 128, 128);
chart.setBackgroundInPlotArea(color);

2.2.4. Orientation

Orientation of chart is a state indicating whether chart orientation is horizontal or vertical. The horizontal orientation means that the direction of X axis (Jan, Feb, Mar,...) is horizontal as shown on the left hand side in the screenshot below. The vertical orientation means that the direction of X axis is vertical as shown on the right hand side in the screenshot.

The orientation is set with the following value.

description value
horizontal orientation SWT.HORIZONTAL
vertical orientation SWT.VERTICAL

The folowing example code sets the vertical orientation.

chart.setOrientation(SWT.VERTICAL);

2.3. Axis Set

Axis Set is a container of axes.

The folowing example code gets axis set from chart.

IAxisSet axisSet = chart.getAxisSet();

2.3.1. Axis Id

Axis Id is an identifier of axis. By default, axis set has X axis and Y axis with axis id 0. SWTChart supports multiple axes (e.g. having one X Axis and two Y axes), and axis id will be automatically assigned when creating additional axes.

int axisId = axisSet.createYAxis();

You can get an axis from axis set with axis id as below.

IAxis yAxis = axisSet.getYAxis(axisId);

You can delete the created axis in axis set with axis id as below.

axisSet.deleteYAxis(axisId);

2.3.2. Adjust Range

Adjust Range of axis set is an operation to adjust the range of all axes so that all series are fully shown. If you want to adjust the range of only a certain axis, please refer to 2.4.5.

axisSet.adjustRange();

2.3.3. Zoom

Zoom of axis set is an operation to zoom in or out the range of all axes. If you want to zoom only a certain axis, please refer to 2.4.6.

axisSet.zoomIn();
axisSet.zoomOut();

2.4. Axis

2.4.1. Direction

Direction of axis can be either X or Y. The direction cannot be changed once it is set when axis is created. Even if changing the orientation of chart, the direction of axis is persistent.

2.4.2. Position

Position of axis can be either primary or secondary. Primary means the position at bottom or left side of chart, while secondary means the position top or right side of chart. By default, the position is primary.

The position is set with the following enum value.

description value
primary position Position.Primary
secondary position Position.Secondary

The folowing example code changes the position of Y axis from primary to secondary.

IAxis yAxis = axisSet.getYAxis(0);
yAxis.setPosition(Position.Secondary);

2.4.3. Range

Range of axis is a range shown on plot area.

The folowing example code sets the range of X axis between 1.5 and 3.5.

IAxis xAxis = axisSet.getXAxis(0);
xAxis.setRange(new Range(1.5, 3.5));

2.4.4. Log Scale

Log Scale is a state that the axis scale is logarithmic.

The folowing example code enables the log scale for Y axis.

IAxis yAxis = axisSet.getYAxis(0);
yAxis.enableLogScale(true);

2.4.5. Adjust Range

Adjust Range of axis is an operation to adjust the range of axis.

The folowing example code adjusts the range of Y axis.

IAxis yAxis = axisSet.getYAxis(0);
yAxis.adjustRange();

2.4.6. Zoom

Zoom of axis is an operation to zoom in or out the range of axis.

The folowing example code zooms in and out the range of Y axis.

IAxis yAxis = axisSet.getYAxis(0);
yAxis.zoomIn();
yAxis.zoomOut();

The folowing example code zooms in and out the range of Y axis at the given coordinate instead of at center of axis range.

IAxis yAxis = axisSet.getYAxis(0);
yAxis.zoomIn(0.5);
yAxis.zoomOut(0.5);

2.4.7. Scroll

Scroll of axis is an operation to scroll up or down the range of axis.

The folowing example code scrolls up or down the range of Y axis.

IAxis yAxis = axisSet.getYAxis(0);
yAxis.scrollUp();
yAxis.scrollDown();

2.4.8. Category

Category is a type of axis to show a chart categorizing multile series. It retuires category series to be shown as tick labels on axis.

The folowing example code enables a category axis with cagegory series (Jan, Feb,...).

IAxis xAxis = axisSet.getXAxis(0);
xAxis.setCategorySeries(new String[] { "Jan", "Feb", "Mar", "Apr", "May" });
xAxis.enableCategory(true)

2.5. Axis Tick

2.5.1. Foreground

Foreground of axis tick is a color of axis tick marks and labels. The foreground is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the foreground color of X axis tick to red.

IAxisTick xTick = axisSet.getXAxis(0).getTick();

Color color = new Color(Display.getDefault(), 255, 0, 0);
xTick.setForeground(color);

2.5.2. Font

Font of axis tick is a font of axis tick labels which is set with org.eclipse.swt.graphics.Font.

The folowing example code sets the font size of X axis tick to 14 points.

IAxisTick xTick = axisSet.getXAxis(0).getTick();

Font font = new Font(Display.getDefault(), "Tahoma", 14, SWT.BOLD);
xTick.setFont(font);

2.5.3. Visibility

Visibility of axis tick is a state indicating whether to show axis line, axis tick marks and labels.

The folowing example code sets the X axis tick invisible.

IAxisTick xTick = axisSet.getXAxis(0).getTick();
xTick.setVisible(false);

2.5.4. Tick Mark Step Hint

Tick Mark Step Hint is a property to give a hint for calculating the size of tick mark step.

The folowing example code sets the tick mark step hint to 20 pixels.

IAxisTick xTick = axisSet.getXAxis(0).getTick();
xTick.setTickMarkStepHint(20);

2.5.5. Format

Format is a property to format the axis tick labels. java.text.DecimalFormat and java.text.DateFormat should be used for double[] and java.util.Date[] respectively.

The folowing example code sets the format for double array to attach the unit "M" to Y axis tick value.

IAxisTick yTick = axisSet.getYAxis(0).getTick();
yTick.setFormat(new DecimalFormat("#####.#M"));

The folowing example code sets the format for Date array to show hour and minute.

lineSeries.setXDateSeries(xSeries); // xSeries is an array of java.util.Date
IAxisTick xTick = axisSet.getXAxis(0).getTick();

DateFormat format = new SimpleDateFormat("HH:mm");
xTick.setFormat(format);

2.6. Grid

2.6.1. Foreground

Foreground of grid is a color of grid line which is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the foreground of X grid to red.

IGrid xGrid = axisSet.getXAxis(0).getGrid();

Color color = new Color(Display.getDefault(), 255, 0, 0);
xGrid.setForeground(color);

2.6.2. Style

Style of grid is a line style of grid line defined with the enum LineStyle.

description value image
solid LineStyle.SOLID
dash LineStyle.DASH
dot LineStyle.DOT
dash dot LineStyle.DASHDOT
dash dot dot LineStyle.DASHDOTDOT
none LineStyle.NONE

The folowing example code sets the line style of X grid to solid.

IGrid xGrid = axisSet.getXAxis(0).getGrid();
xGrid.setStyle(LineStyle.SOLID);

2.7. Series Set

Series Set is a container of series.

The folowing example code gets series set from chart.

ISeriesSet seriesSet = chart.getSeriesSet();

2.7.1. Series Id

Series Id is an identifier of series. When creating series, series type and series id have to be given.

String seriesId = "line series";
ISeries series = seriesSet.createSeries(SeriesType.LINE, seriesId);

You can get series from series set with series id as below.

ISeries series = seriesSet.getSeries(seriesId);

You can delete series in series set with series id as below.

seriesSet.deleteSeries(seriesId);

2.7.2. Series Order

Series Order is an order to draw series on chart. Typically, the series order can be important when enabling stack series or when series is overlaid by other series.

The series order is determined by the order of creating series, and can be re-ordered with following methods.

seriesSet.bringForward("line series");
seriesSet.sendBackward("line series");
seriesSet.bringToFront("line series");
seriesSet.sendToBack("line series");

2.8. Series

2.8.1. Visibility

Visibility of series is a state indicating whether to show series.

The folowing example code sets the series invisible.

ISeries series = seriesSet.getSeries(seriesId);
series.setVisible(false);

2.8.2. Series Type

Series Type is a property which can be either line series SeriesType.LINE or bar series SeriesType.BAR. When creating series, series type and series id have to be given.

String seriesId = "line series";
ISeries series = seriesSet.createSeries(SeriesType.BAR, seriesId);

2.8.3. Stack

Stack of series is a property to stack multiple series.

The folowing example code stacks the bar series.

barSeries1.enableStack(true);
barSeries2.enableStack(true);

2.9. Line Series

2.9.1. Symbol Type

Symbol Type is a tyle of plot symbol defined with the enum PlotSymbolType.

description value image
circle PlotSymbolType.CIRCLE
square PlotSymbolType.SQUARE
diamond PlotSymbolType.DIAMOND
triangle PlotSymbolType.TRIANGLE
inverted triangle PlotSymbolType.INVERTED_TRIANGLE
cross PlotSymbolType.CROSS
plus PlotSymbolType.PLUS
none PlotSymbolType.NONE

The folowing example code sets the symbol type to square.

series.setSymbolType(PlotSymbolType.SQUARE);

2.9.2. Symbol Size

Symbol Size is a side length of square to draw series symbol. If symbol type is circle, symbol size is equal to diameter.

The folowing example code sets the symbol size to 6 pixels.

series.setSymbolSize(6);

2.9.3. Symbol Color

Symbol Color is a color of series symbol which is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the symbol color to red.

Color color = new Color(Display.getDefault(), 255, 0, 0);
series.setSymbolColor(color);

The following example code sets the different symbol color for each data point.

Color[] colors = ...
series.setSymbolColor(colors);

2.9.4. Line Style

Line Style of line series is a line style defined with the enum LineStyle.

description value image
solid LineStyle.SOLID
dash LineStyle.DASH
dot LineStyle.DOT
dash dot LineStyle.DASHDOT
dash dot dot LineStyle.DASHDOTDOT
none LineStyle.NONE

The folowing example code sets the line style to dot.

series.setLineStyle(LineStyle.DOT);

2.9.5. Line Color

Line Color is a color of line series which is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the line color to red.

Color color = new Color(Display.getDefault(), 255, 0, 0);
series.setLineColor(color);

2.9.6. Line Width

Line Width of line series is a width to draw line and plot symbol.

The folowing example code sets the line width to 3 pixels.

series.setLineWidth(3);

2.9.7. Anti-Aliasing

Anti-Aliasing of line series is a property to set the anti-aliasing value for drawing line of line series.

The anti-aliasing is set with the following value.

description value
enable anti-aliasing SWT.ON
disable anti-aliasing SWT.OFF
set anti-aliasing default SWT.DEFAULT

If number of data points is too large, the series is drawn as a collection of dots rather than lines. In this case, the anti-alias doesn't really make effect, and just causes performance degradation. Therefore, client code may automatically enable/disable the anti-alias for each series depending on the number of data points, or alternatively may let end-user configure it.

The folowing example code enables anti-aliasing for line series.

series.setAntialias(SWT.ON);

2.9.8. Area

Area of line series is a property to fill between line series and axis with color. If there are multiple stacked series with category axis, the area between line series will be filled.

The folowing example code enables the area chart.

series.enableArea(true);

2.9.9. Step

Step of line series is a property to show line with step.

The folowing example code enables the step chart.

series.enableStep(true);

2.10. Bar Series

2.10.1. Bar Padding

Bar Padding is a padding size of bar in percentage. By default, the bar padding is 20%.

The folowing example code sets the bar padding to 50%.

series.setBarPadding(50);

2.10.2. Bar Color

Bar Color is a color of bar series which is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the bar color to right green.

Color color = new Color(Display.getDefault(), 80, 240, 180);
series.setBarColor(color);

2.11. Series Label

Series Label is a label shown next to each plot.

ISeriesLabel seriesLabel = series.getLabel();

2.11.1. Format

Format is a format defined in java.text.DecimalFormat to show series label.

The folowing example code sets the format of series label to show with fixed point numbers.

seriesLabel.setFormat("##.0");

The folowing example code sets the different format for each data point.

String[] formats = ...
seriesLabel.setFormat(formats);

2.11.2. Foreground

Foreground of series label is a color of series label which is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the color of series label to red.

Color color = new Color(Display.getDefault(), 255, 0, 0);
seriesLabel.setForeground(color);

2.11.3. Font

Font of series label is set with org.eclipse.swt.graphics.Font.

The folowing example code sets the font of series label.

Font font = new Font(Display.getDefault(), "Tahoma", 10, SWT.BOLD);
seriesLabel.setFont(font);

2.11.4. Visibility

Visibility of series label is a state indicating whether to show series label.

The folowing example code sets the series label invisible.

seriesLabel.setVisible(false);

2.12. Error Bar

Error Bar is an bar typically used to indicate standard deviation or standard error.

ISeries series = ...
IErrorBar xErrorBar = series.getXErrorBar();
IErrorBar yErrorBar = series.getYErrorBar();

2.12.1. Type

Type of error bar is a property defined with the enum ErrorBarType.

description value image
both ErrorBarType.BOTH
plus ErrorBarType.PLUS
minus ErrorBarType.MINUS

The folowing example code sets the error bar type to both.

yErrorBar.setType(ErrorBarType.BOTH);

2.12.2. Color

Color of error bar is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the color of error bar to red.

Color color = new Color(Display.getDefault(), 255, 0, 0);
yErrorBar.setColor(color);

2.12.3. Line Width

Line Width is a width to draw line of error bar.

The folowing example code sets the line width to 3 pixels.

yErrorBar.setLineWidth(3);

2.12.4. Error Value

Error Value can be set either as a common value for all data points or as different plus/minus value for each data point.

The folowing example code sets the error 0.1 for all data points.

yErrorBar.setError(0.1);

The folowing example code sets the different error for each data point.

yErrorBar.setPlusErrors(plusErrors);// plusError is an array of double
yErrorBar.setMinusErrors(minusErrors);// minusError is an array of double

2.12.5. Visibility

Visibility of error bar is a state indicating whether to show error bar.

The folowing example code sets the series label visible.

yErrorBar.setVisible(true);

2.13. Legend

Legend is a legend shown next to plot area.

ILegend legend = chart.getLegend();

2.13.1. Position

Position of legend can be set with the following enum value.

description value
top SWT.TOP
bottom SWT.BOTTOM
left SWT.LEFT
right SWT.RIGHT

The folowing example code changes the position of legend from right to top.

legend.setPosition(SWT.TOP);

2.13.2. Foreground

Foreground of legend is a color of series ids on legend which is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the foreground color of legend to red.

Color color = new Color(Display.getDefault(), 255, 0, 0);
legend.setForeground(color);

2.13.3. Background

Background of legend is a background color of legend area which is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the background color of legend to green.

Color color = new Color(Display.getDefault(), 80, 240, 180);
legend.setBackground(color);

2.13.4. Font

Font of legend is a font of series ids on legend which is set with org.eclipse.swt.graphics.Font.

The folowing example code sets the font size of legend to 12 points.

Font font = new Font(Display.getDefault(), "Tahoma", 12, SWT.BOLD);
legend.setFont(font);

2.13.5. Visibility

Visibility of legend is a state indicating whether to show legend.

The folowing example code sets the legend visible.

legend.setVisible(true);

2.14. Title

Title is shown at the top of chart as a chart title, and also shown at each title as a axis title.

The folowing example code gets the graph title, X axis title and Y axis title.

ITitle graphTitle = chart.getTitle();
ITitle xAxisTitle = xAxis.getTitle();
ITitle yAxisTitle = yAxis.getTitle();

2.14.1. Text

Text of title is set with java.lang.String.

The folowing example code sets the text of graph title, X axis title and Y axis title.

graphTitle.setText("Chart");
xAxisTitle.setText("X Axis");
yAxisTitle.setText("Y Axis");

2.14.2. Foreground

Foreground of title is a color of title which is set with org.eclipse.swt.graphics.Color.

The folowing example code sets the foreground of titles to red.

Color color = new Color(Display.getDefault(), 255, 0, 0);
graphTitle.setForeground(color);
xAxisTitle.setForeground(color);
yAxisTitle.setForeground(color);

2.14.3. Font

Font of title is set with org.eclipse.swt.graphics.Font.

The folowing example code sets the font size of title to 16 points, and sets the font style to italic.

Font font = new Font(Display.getDefault(), "Tahoma", 16, SWT.ITALIC);
graphTitle.setFont(font);
xAxisTitle.setFont(font);
yAxisTitle.setFont(font);

2.14.4. Visibility

Visibility of title is a state indicating whether to show title.

The folowing example code sets the titles invisible.

graphTitle.setVisible(false);
xAxisTitle.setVisible(false);
yAxisTitle.setVisible(false);

3. Examples

3.1. Showing line chart

// create a chart
Chart chart = new Chart(composite, SWT.NONE);
    
// set titles
chart.getTitle().setText("Line Chart Example");
chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points");
chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");

// create line series
ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet()
    .createSeries(SeriesType.LINE, "line series");
lineSeries.setYSeries(ySeries);

// adjust the axis range
chart.getAxisSet().adjustRange();

3.2. Showing bar series

// create a chart
Chart chart = new Chart(composite, SWT.NONE);
    
// set titles
chart.getTitle().setText("Bar Chart Example");
chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points");
chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");

// create bar series
IBarSeries barSeries = (IBarSeries) chart.getSeriesSet()
    .createSeries(SeriesType.BAR, "bar series");
barSeries.setYSeries(ySeries);

// adjust the axis range
chart.getAxisSet().adjustRange();

3.3. Showing scatter chart

// create a chart
Chart chart = new Chart(composite, SWT.NONE);
        
// set titles
chart.getTitle().setText("Scatter Chart Example");
chart.getAxisSet().getXAxis(0).getTitle().setText("Score A");
chart.getAxisSet().getYAxis(0).getTitle().setText("Score B");

// create scatter series
ILineSeries scatterSeries = (ILineSeries) chart.getSeriesSet()
        .createSeries(SeriesType.LINE, "scatter series");
scatterSeries.setLineStyle(LineStyle.NONE);
scatterSeries.setXSeries(xSeries);
scatterSeries.setYSeries(ySeries);

// adjust the axis range
chart.getAxisSet().adjustRange();

3.4. Showing area chart

// create a chart
Chart chart = new Chart(composite, SWT.NONE);
        
// set titles
chart.getTitle().setText("Area Chart Example");

// create line series
ILineSeries lineSeries1 = (ILineSeries) chart.getSeriesSet()
        .createSeries(SeriesType.LINE, "line series 1");
scatterSeries.setYSeries(ySeries1);
lineSeries1.setLineColor(Display.getDefault().getSystemColor(
                SWT.COLOR_RED));
lineSeries1.enableArea(true);

ILineSeries lineSeries2 = (ILineSeries) chart.getSeriesSet()
        .createSeries(SeriesType.LINE, "line series 2");
lineSeries2.setYSeries(ySeries2);
lineSeries2.enableArea(true);
    
// adjust the axis range
chart.getAxisSet().adjustRange();

3.5. Showing step chart

// create a chart
Chart chart = new Chart(composite, SWT.NONE);
        
// set titles
chart.getTitle().setText("Step Chart Example");

// create line series
ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet()
        .createSeries(SeriesType.LINE, "line series");
lineSeries.setYSeries(ySeries);
lineSeries.setSymbolType(PlotSymbolType.NONE);
lineSeries.enableStep(true);
    
// adjust the axis range
chart.getAxisSet().adjustRange();

3.6. Showing stack series

// create a chart
Chart chart = new Chart(composite, SWT.NONE);
        
// set titles
chart.getTitle().setText("Stack Series Example");
chart.getAxisSet().getXAxis(0).getTitle().setText("Month");
chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");

// set category
chart.getAxisSet().getXAxis(0).enableCategory(true);
chart.getAxisSet().getXAxis(0).setCategorySeries(
        new String[] { "Jan", "Feb", "Mar", "Apr", "May" });

// create bar series
IBarSeries barSeries1 = (IBarSeries) chart.getSeriesSet().createSeries(
        SeriesType.BAR, "bar series 1");
barSeries1.setYSeries(ySeries1);
barSeries1.setBarColor(Display.getDefault().getSystemColor(
                SWT.COLOR_GREEN));

IBarSeries barSeries2 = (IBarSeries) chart.getSeriesSet().createSeries(
        SeriesType.BAR, "bar series 2");
barSeries2.setYSeries(ySeries2);

// enable stack series
barSeries1.enableStack(true);
barSeries2.enableStack(true);

// adjust the axis range
chart.getAxisSet().adjustRange();

3.7. Showing axis with log scale

// create a chart
Chart chart = new Chart(composite, SWT.NONE);
        
// set titles
chart.getTitle().setText("Log Scale Example");
chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points");
chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");

// create line series
ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet()
        .createSeries(SeriesType.LINE, "line series");
lineSeries.setYSeries(ySeries);

// set log scale
chart.getAxisSet().getYAxis(0).enableLogScale(true);

// adjust the axis range
chart.getAxisSet().adjustRange();

3.8. Setting orientation

// create a chart
Chart chart = new Chart(composite, SWT.NONE);

// set the chart orientation
chart.setOrientation(SWT.VERTICAL);

// set titles
chart.getTitle().setText("Orientation Example");
chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points");
chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");

// create bar series
IBarSeries barSeries = (IBarSeries) chart.getSeriesSet()
        .createSeries(SeriesType.BAR, "bar series");
barSeries.setYSeries(ySeries);

// adjust the axis range
chart.getAxisSet().adjustRange();

3.9. Showing category axis

// create a chart
Chart chart = new Chart(composite, SWT.NONE);
    
// set titles
chart.getTitle().setText("Category Axis Example");
chart.getAxisSet().getXAxis(0).getTitle().setText("Month");
chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");

// set category
chart.getAxisSet().getXAxis(0).enableCategory(true);
chart.getAxisSet().getXAxis(0).setCategorySeries(
        new String[] { "Jan", "Feb", "Mar", "Apr", "May" });

// create bar series
IBarSeries barSeries1 = (IBarSeries) chart.getSeriesSet().createSeries(
        SeriesType.BAR, "bar series 1");
barSeries1.setYSeries(ySeries1);
barSeries1.setBarColor(Display.getDefault().getSystemColor(
        SWT.COLOR_GREEN));

IBarSeries barSeries2 = (IBarSeries) chart.getSeriesSet().createSeries(
        SeriesType.BAR, "bar series 2");
barSeries2.setYSeries(ySeries2);

// adjust the axis range
chart.getAxisSet().adjustRange();

3.10. Showing series label

// create a chart
Chart chart = new Chart(composite, SWT.NONE);

// set titles
chart.getTitle().setText("Series Label Example");
chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points");
chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");

// create line series
ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet()
    .createSeries(SeriesType.LINE, "line series");
lineSeries.setYSeries(ySeries);

// set label visible
lineSeries.getLabel().setVisible(true);

// adjust the axis range
chart.getAxisSet().adjustRange();

3.11. Showing error bars

// create a chart
Chart chart = new Chart(composite, SWT.NONE);

// create line series
ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet()
    .createSeries(SeriesType.LINE, "line series");
lineSeries.setYSeries(ySeries);
    
// set error bars
IErrorBar errorBar = series.getYErrorBar();
errorBar.setVisible(true);
errorBar.setError(0.1);

// adjust the axis range
chart.getAxisSet().adjustRange();

3.12. Showing multiple axes

// create a chart
Chart chart = new Chart(composite, SWT.NONE);
    
// set titles
chart.getTitle().setText("Multiple Axes Example");
chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points");
chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude 1");

// create second Y axis
int axisId = chart.getAxisSet().createYAxis();

// set the properties of second Y axis
IAxis yAxis2 = chart.getAxisSet().getYAxis(axisId);
yAxis2.setPosition(Position.Secondary);
final Color RED = Display.getDefault().getSystemColor(SWT.COLOR_RED);
yAxis2.getTick().setForeground(RED);
yAxis2.getTitle().setForeground(RED);
yAxis2.getTitle().setText("Amplitude 2");

// create line series
ILineSeries lineSeries1 = (ILineSeries) chart.getSeriesSet()
        .createSeries(SeriesType.LINE, "line series 1");
lineSeries1.setYSeries(ySeries1);
ILineSeries lineSeries2 = (ILineSeries) chart.getSeriesSet()
        .createSeries(SeriesType.LINE, "line series 2");
lineSeries2.setYSeries(ySeries2);
lineSeries2.setLineColor(RED);

// assign series to second Y axis
lineSeries2.setYAxisId(axisId);

// adjust the axis range
chart.getAxisSet().adjustRange();

4. References

4.1. Javadoc

Browse SWTChart v0.10.0 API References.

4.2. Links