Search in sources :

Example 6 with Chart

use of org.eclipse.swtchart.Chart in project swtchart by eclipse.

the class OrientationExample method createChart.

/**
 * create the chart.
 *
 * @param parent
 *            The parent composite
 * @return The created chart
 */
public static Chart createChart(Composite parent) {
    // create a chart
    Chart chart = new Chart(parent, SWT.NONE);
    // set the chart orientation
    chart.setOrientation(SWT.VERTICAL);
    // set titles
    chart.getTitle().setText("Orientation");
    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();
    return chart;
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) Chart(org.eclipse.swtchart.Chart)

Example 7 with Chart

use of org.eclipse.swtchart.Chart in project swtchart by eclipse.

the class ScatterChartExample method createChart.

/**
 * create the chart.
 *
 * @param parent
 *            The parent composite
 * @return The created chart
 */
public static Chart createChart(Composite parent) {
    // create a chart
    Chart chart = new Chart(parent, SWT.NONE);
    // set titles
    chart.getTitle().setText("Scatter Chart");
    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();
    return chart;
}
Also used : ILineSeries(org.eclipse.swtchart.ILineSeries) Chart(org.eclipse.swtchart.Chart)

Example 8 with Chart

use of org.eclipse.swtchart.Chart in project swtchart by eclipse.

the class AxisTickBoundsExample method createChart.

/**
 * create the chart.
 *
 * @param parent
 *            The parent composite
 * @return The created chart
 */
public static Chart createChart(Composite parent) {
    // create a chart
    final Chart chart = new Chart(parent, SWT.NONE);
    chart.getTitle().setText("Axis Tick Bounds");
    // create bar series
    IBarSeries series1 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series");
    series1.setYSeries(ySeries);
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    // add mouse move listener to chart
    chart.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent e) {
            for (IAxis axis : chart.getAxisSet().getAxes()) {
                Rectangle r = axis.getTick().getBounds();
                // check if mouse cursor is on axis tick
                if (r.x < e.x && e.x < r.x + r.width && r.y < e.y && e.y < r.y + r.height) {
                    // get pixel coordinate on axis tick
                    int pixelCoord;
                    if (axis.getDirection() == Direction.X) {
                        pixelCoord = e.x - r.x;
                    } else {
                        pixelCoord = e.y - r.y;
                    }
                    // get data coordinate
                    double dataCoord = axis.getDataCoordinate(pixelCoord);
                    // show tool-tip
                    chart.setToolTipText(String.valueOf(dataCoord));
                    return;
                }
            }
            chart.setToolTipText(null);
        }
    });
    return chart;
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseEvent(org.eclipse.swt.events.MouseEvent) IBarSeries(org.eclipse.swtchart.IBarSeries) Rectangle(org.eclipse.swt.graphics.Rectangle) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis)

Example 9 with Chart

use of org.eclipse.swtchart.Chart in project swtchart by eclipse.

the class CategoryExample method createChart.

/**
 * create the chart.
 *
 * @param parent
 *            The parent composite
 * @return The created chart
 */
public static Chart createChart(Composite parent) {
    // create a chart
    Chart chart = new Chart(parent, SWT.NONE);
    // set titles
    chart.getTitle().setText("Category Axis");
    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();
    return chart;
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) Chart(org.eclipse.swtchart.Chart)

Example 10 with Chart

use of org.eclipse.swtchart.Chart in project swtchart by eclipse.

the class ErrorBarsExample method createChart.

/**
 * create the chart.
 *
 * @param parent
 *            The parent composite
 * @return The created chart
 */
public static Chart createChart(Composite parent) {
    // create a chart
    Chart chart = new Chart(parent, SWT.NONE);
    chart.getTitle().setText("Error Bars");
    // create series
    ISeries series = chart.getSeriesSet().createSeries(SeriesType.LINE, "line series");
    series.setYSeries(ySeries);
    // set error bars
    IErrorBar errorBar = series.getYErrorBar();
    errorBar.setVisible(true);
    errorBar.setError(0.1);
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    return chart;
}
Also used : IErrorBar(org.eclipse.swtchart.IErrorBar) ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart)

Aggregations

Chart (org.eclipse.swtchart.Chart)45 Test (org.junit.Test)14 ILineSeries (org.eclipse.swtchart.ILineSeries)13 ISeries (org.eclipse.swtchart.ISeries)11 IAxis (org.eclipse.swtchart.IAxis)8 XYDataProviderBaseTest (org.eclipse.tracecompass.tmf.ui.swtbot.tests.views.xychart.XYDataProviderBaseTest)8 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)7 IBarSeries (org.eclipse.swtchart.IBarSeries)7 TmfCommonXAxisChartViewer (org.eclipse.tracecompass.tmf.ui.viewers.xychart.linechart.TmfCommonXAxisChartViewer)6 IViewPart (org.eclipse.ui.IViewPart)6 MouseEvent (org.eclipse.swt.events.MouseEvent)5 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)5 SWTBotView (org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView)5 ISeriesSet (org.eclipse.swtchart.ISeriesSet)4 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)4 Nullable (org.eclipse.jdt.annotation.Nullable)3 IAction (org.eclipse.jface.action.IAction)3 Point (org.eclipse.swt.graphics.Point)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 SWTBotTree (org.eclipse.swtbot.swt.finder.widgets.SWTBotTree)3