Search in sources :

Example 46 with ISeries

use of org.eclipse.swtchart.ISeries 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 47 with ISeries

use of org.eclipse.swtchart.ISeries 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 48 with ISeries

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

the class ScrollableChart method deleteSeries.

@Override
public void deleteSeries() {
    baseChart.suspendUpdate(true);
    for (ISeries series : baseChart.getSeriesSet().getSeries()) {
        baseChart.deleteSeries(series.getId());
    }
    baseChart.suspendUpdate(false);
    redraw();
}
Also used : ISeries(org.eclipse.swtchart.ISeries)

Example 49 with ISeries

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

the class MassSpectrumChart method getBarSeriesIonList.

private List<BarSeriesIon> getBarSeriesIonList() {
    List<BarSeriesIon> barSeriesIons = new ArrayList<BarSeriesIon>();
    // 
    int widthPlotArea = getBaseChart().getPlotArea().getBounds().width;
    ISeries[] series = getBaseChart().getSeriesSet().getSeries();
    for (ISeries barSeries : series) {
        if (barSeries != null) {
            // 
            double[] xSeries = barSeries.getXSeries();
            double[] ySeries = barSeries.getYSeries();
            int size = barSeries.getXSeries().length;
            // 
            for (int i = 0; i < size; i++) {
                Point point = barSeries.getPixelCoordinates(i);
                if (point.x >= 0 && point.x <= widthPlotArea) {
                    barSeriesIons.add(new BarSeriesIon(xSeries[i], ySeries[i], point));
                }
            }
        }
    }
    return barSeriesIons;
}
Also used : ArrayList(java.util.ArrayList) BarSeriesIon(org.eclipse.swtchart.extensions.internal.support.BarSeriesIon) Point(org.eclipse.swt.graphics.Point) ISeries(org.eclipse.swtchart.ISeries) Point(org.eclipse.swt.graphics.Point)

Example 50 with ISeries

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

the class AbstractExtendedChart method deleteSeries.

@Override
public void deleteSeries(String id) {
    ISeriesSet seriesSet = getSeriesSet();
    if (seriesSet.getSeries(id) != null) {
        resetCoordinates();
        seriesSet.deleteSeries(id);
        seriesSettingsMap.remove(id);
        for (ISeries series : seriesSet.getSeries()) {
            calculateCoordinates(series);
        }
    }
}
Also used : ISeriesSet(org.eclipse.swtchart.ISeriesSet) ISeries(org.eclipse.swtchart.ISeries)

Aggregations

ISeries (org.eclipse.swtchart.ISeries)60 Point (org.eclipse.swt.graphics.Point)21 ISeriesSet (org.eclipse.swtchart.ISeriesSet)11 Chart (org.eclipse.swtchart.Chart)10 IAxis (org.eclipse.swtchart.IAxis)9 Range (org.eclipse.swtchart.Range)9 BaseChart (org.eclipse.swtchart.extensions.core.BaseChart)8 Color (org.eclipse.swt.graphics.Color)5 IBarSeries (org.eclipse.swtchart.IBarSeries)5 ILineSeries (org.eclipse.swtchart.ILineSeries)5 IAxisSettings (org.eclipse.swtchart.extensions.core.IAxisSettings)5 Rectangle (org.eclipse.swt.graphics.Rectangle)4 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)3 GC (org.eclipse.swt.graphics.GC)3 Test (org.junit.Test)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2