Search in sources :

Example 26 with Chart

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

the class MultipleAxesExample 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("Multiple Axes");
    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();
    return chart;
}
Also used : Color(org.eclipse.swt.graphics.Color) ILineSeries(org.eclipse.swtchart.ILineSeries) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis)

Example 27 with Chart

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

the class RunAllExamples method createList.

private static void createList(String tabName, final Vector<Chart> charts, TabFolder tabFolder, final StackLayout layout, final Composite composite) {
    final List list = new List(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL);
    TabItem basicTabItem = new TabItem(tabFolder, SWT.NONE);
    basicTabItem.setText(tabName);
    basicTabItem.setControl(list);
    for (Chart chart : charts) {
        list.add(chart.getTitle().getText());
    }
    list.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            Chart chart = charts.get(list.getSelectionIndex());
            chart.getAxisSet().adjustRange();
            layout.topControl = chart;
            composite.layout();
        }
    });
}
Also used : TabItem(org.eclipse.swt.widgets.TabItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) Chart(org.eclipse.swtchart.Chart)

Example 28 with Chart

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

the class SeriesLabelExample 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("Series Label");
    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();
    return chart;
}
Also used : ILineSeries(org.eclipse.swtchart.ILineSeries) Chart(org.eclipse.swtchart.Chart)

Example 29 with Chart

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

the class StackSeriesExample 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("Stack Series");
    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();
    return chart;
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) Chart(org.eclipse.swtchart.Chart)

Example 30 with Chart

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

the class StepChartExample 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("Step Chart");
    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);
    lineSeries.setSymbolType(PlotSymbolType.NONE);
    lineSeries.enableStep(true);
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    return chart;
}
Also used : ILineSeries(org.eclipse.swtchart.ILineSeries) 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