Search in sources :

Example 1 with Chart

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

the class CustomPaintListenerExample 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("Custom Paint Listener");
    ISeries lineSeries = chart.getSeriesSet().createSeries(SeriesType.LINE, "line series");
    lineSeries.setYSeries(ySeries);
    // add paint listeners
    IPlotArea plotArea = (IPlotArea) chart.getPlotArea();
    plotArea.addCustomPaintListener(new FrontPaintListener());
    plotArea.addCustomPaintListener(new BehindPaintListener());
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    return chart;
}
Also used : IPlotArea(org.eclipse.swtchart.IPlotArea) ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart)

Example 2 with Chart

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

the class DataToPixelConversionExample 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("Data To Pixel Conversion");
    // get Y axis
    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 paint listener to draw threshold
    chart.getPlotArea().addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            int y = yAxis.getPixelCoordinate(0.65);
            e.gc.drawLine(0, y, e.width, y);
            e.gc.drawText("y=0.65", MARGIN, y + MARGIN);
        }
    });
    return chart;
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) ILineSeries(org.eclipse.swtchart.ILineSeries) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis)

Example 3 with Chart

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

the class LegendBoundsExample 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("Legend Bounds");
    // create bar series
    IBarSeries series1 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series 1");
    series1.setYSeries(ySeries1);
    series1.setBarColor(Display.getDefault().getSystemColor(SWT.COLOR_GREEN));
    IBarSeries series2 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series 2");
    series2.setYSeries(ySeries2);
    series2.setBarColor(Display.getDefault().getSystemColor(SWT.COLOR_MAGENTA));
    IBarSeries series3 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series 3");
    series3.setYSeries(ySeries3);
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    // add mouse move listener to legend
    final Control legend = (Control) chart.getLegend();
    legend.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent e) {
            for (ISeries series : chart.getSeriesSet().getSeries()) {
                Rectangle r = chart.getLegend().getBounds(series.getId());
                if (r.x < e.x && e.x < r.x + r.width && r.y < e.y && e.y < r.y + r.height) {
                    legend.setToolTipText(series.getId());
                    return;
                }
            }
        }
    });
    return chart;
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) Control(org.eclipse.swt.widgets.Control) MouseEvent(org.eclipse.swt.events.MouseEvent) IBarSeries(org.eclipse.swtchart.IBarSeries) Rectangle(org.eclipse.swt.graphics.Rectangle) ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart)

Example 4 with Chart

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

the class SymbolBoundsExample 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("Symbol Bounds");
    // create line series
    ILineSeries series1 = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "series 1");
    series1.setYSeries(ySeries1);
    ILineSeries series2 = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "series 2");
    series2.setYSeries(ySeries2);
    series2.setLineColor(Display.getDefault().getSystemColor(SWT.COLOR_RED));
    // 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()) {
                for (int i = 0; i < series.getYSeries().length; i++) {
                    Point p = series.getPixelCoordinates(i);
                    double distance = Math.sqrt(Math.pow(e.x - p.x, 2) + Math.pow(e.y - p.y, 2));
                    if (distance < ((ILineSeries) series).getSymbolSize()) {
                        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) ILineSeries(org.eclipse.swtchart.ILineSeries) Point(org.eclipse.swt.graphics.Point) ISeries(org.eclipse.swtchart.ISeries) Chart(org.eclipse.swtchart.Chart) Point(org.eclipse.swt.graphics.Point)

Example 5 with Chart

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

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

Aggregations

Chart (org.eclipse.swtchart.Chart)46 Test (org.junit.Test)14 ILineSeries (org.eclipse.swtchart.ILineSeries)13 ISeries (org.eclipse.swtchart.ISeries)11 IAxis (org.eclipse.swtchart.IAxis)9 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 MouseEvent (org.eclipse.swt.events.MouseEvent)6 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)6 TmfCommonXAxisChartViewer (org.eclipse.tracecompass.tmf.ui.viewers.xychart.linechart.TmfCommonXAxisChartViewer)6 IViewPart (org.eclipse.ui.IViewPart)6 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 Control (org.eclipse.swt.widgets.Control)3