Search in sources :

Example 1 with ILineSeries

use of org.eclipse.swtchart.ILineSeries 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 2 with ILineSeries

use of org.eclipse.swtchart.ILineSeries 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 3 with ILineSeries

use of org.eclipse.swtchart.ILineSeries 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)

Example 4 with ILineSeries

use of org.eclipse.swtchart.ILineSeries 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 5 with ILineSeries

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

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

Aggregations

ILineSeries (org.eclipse.swtchart.ILineSeries)29 Chart (org.eclipse.swtchart.Chart)13 Color (org.eclipse.swt.graphics.Color)7 Point (org.eclipse.swt.graphics.Point)5 IAxis (org.eclipse.swtchart.IAxis)5 IBarSeries (org.eclipse.swtchart.IBarSeries)5 ISeries (org.eclipse.swtchart.ISeries)5 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)2 ISeriesSet (org.eclipse.swtchart.ISeriesSet)2 InteractiveChart (org.eclipse.swtchart.extensions.charts.InteractiveChart)2 BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)2 ISeriesData (org.eclipse.swtchart.extensions.core.ISeriesData)2 SeriesException (org.eclipse.swtchart.extensions.exceptions.SeriesException)2 Test (org.junit.Test)2 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 IAction (org.eclipse.jface.action.IAction)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1