Search in sources :

Example 31 with Chart

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

the class BarBoundsExample 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("Bar Bounds");
    // create bar series
    IBarSeries series1 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series 1");
    series1.setYSeries(ySeries1);
    IBarSeries series2 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series 2");
    series2.setYSeries(ySeries2);
    series2.setBarColor(Display.getDefault().getSystemColor(SWT.COLOR_GREEN));
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    // add mouse move listener to open tooltip on data point
    chart.getPlotArea().addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent e) {
            for (ISeries series : chart.getSeriesSet().getSeries()) {
                Rectangle[] rs = ((IBarSeries) series).getBounds();
                for (int i = 0; i < rs.length; i++) {
                    if (rs[i] != null) {
                        if (rs[i].x < e.x && e.x < rs[i].x + rs[i].width && rs[i].y < e.y && e.y < rs[i].y + rs[i].height) {
                            setToolTipText(series, i);
                            return;
                        }
                    }
                }
            }
            chart.getPlotArea().setToolTipText(null);
        }

        private void setToolTipText(ISeries series, int index) {
            chart.getPlotArea().setToolTipText("Series: " + series.getId() + "\nValue: " + series.getYSeries()[index]);
        }
    });
    return chart;
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseEvent(org.eclipse.swt.events.MouseEvent) IBarSeries(org.eclipse.swtchart.IBarSeries) ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart)

Example 32 with Chart

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

the class PxielToDataConversionExample 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("Pxiel To Data Conversion");
    // get axes
    final IAxis xAxis = chart.getAxisSet().getXAxis(0);
    final IAxis yAxis = chart.getAxisSet().getYAxis(0);
    // create line series
    ILineSeries series = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "line series");
    series.setYSeries(ySeries);
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    // add mouse move listener to show mouse position on tooltip
    chart.getPlotArea().addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent e) {
            double x = xAxis.getDataCoordinate(e.x);
            double y = yAxis.getDataCoordinate(e.y);
            chart.getPlotArea().setToolTipText("x:" + x + ", y:" + y);
        }
    });
    return chart;
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseEvent(org.eclipse.swt.events.MouseEvent) ILineSeries(org.eclipse.swtchart.ILineSeries) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis)

Example 33 with Chart

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

the class AngledAxisTickLabelsExample 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("Angled Axis Tick Labels");
    // set category
    chart.getAxisSet().getXAxis(0).enableCategory(true);
    chart.getAxisSet().getXAxis(0).setCategorySeries(cagetorySeries);
    chart.getAxisSet().getXAxis(0).getTick().setTickLabelAngle(45);
    // add bar series
    ISeries barSeries = chart.getSeriesSet().createSeries(SeriesType.BAR, "bar series");
    barSeries.setYSeries(ySeries);
    chart.getAxisSet().adjustRange();
    return chart;
}
Also used : ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart)

Example 34 with Chart

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

the class AreaChartExample 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("Area Chart");
    // create line series
    ILineSeries lineSeries1 = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "line series 1");
    lineSeries1.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();
    return chart;
}
Also used : ILineSeries(org.eclipse.swtchart.ILineSeries) Chart(org.eclipse.swtchart.Chart)

Example 35 with Chart

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

the class BarChartExample 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("Bar Chart");
    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)

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