Search in sources :

Example 1 with IBarSeries

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

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

the class OrientationExample 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 the chart orientation
    chart.setOrientation(SWT.VERTICAL);
    // set titles
    chart.getTitle().setText("Orientation");
    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)

Example 3 with IBarSeries

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

the class AxisTickBoundsExample 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("Axis Tick Bounds");
    // create bar series
    IBarSeries series1 = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR, "series");
    series1.setYSeries(ySeries);
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    // add mouse move listener to chart
    chart.addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent e) {
            for (IAxis axis : chart.getAxisSet().getAxes()) {
                Rectangle r = axis.getTick().getBounds();
                // check if mouse cursor is on axis tick
                if (r.x < e.x && e.x < r.x + r.width && r.y < e.y && e.y < r.y + r.height) {
                    // get pixel coordinate on axis tick
                    int pixelCoord;
                    if (axis.getDirection() == Direction.X) {
                        pixelCoord = e.x - r.x;
                    } else {
                        pixelCoord = e.y - r.y;
                    }
                    // get data coordinate
                    double dataCoord = axis.getDataCoordinate(pixelCoord);
                    // show tool-tip
                    chart.setToolTipText(String.valueOf(dataCoord));
                    return;
                }
            }
            chart.setToolTipText(null);
        }
    });
    return chart;
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseEvent(org.eclipse.swt.events.MouseEvent) IBarSeries(org.eclipse.swtchart.IBarSeries) Rectangle(org.eclipse.swt.graphics.Rectangle) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis)

Example 4 with IBarSeries

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

the class CategoryExample 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("Category Axis");
    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);
    // adjust the axis range
    chart.getAxisSet().adjustRange();
    return chart;
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) Chart(org.eclipse.swtchart.Chart)

Example 5 with IBarSeries

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

the class BaseChart method applySeriesSettings.

private void applySeriesSettings(ISeries dataSeries, ISeriesSettings seriesSettings) {
    if (dataSeries instanceof ILineSeries) {
        ILineSeries lineSeries = (ILineSeries) dataSeries;
        if (seriesSettings instanceof ILineSeriesSettings) {
            /*
				 * Line Series
				 */
            ILineSeriesSettings lineSeriesSettings = (ILineSeriesSettings) seriesSettings;
            applyLineSeriesSettings(lineSeries, lineSeriesSettings);
        } else if (seriesSettings instanceof IScatterSeriesSettings) {
            /*
				 * Scatter Series
				 */
            IScatterSeriesSettings scatterSeriesSettings = (IScatterSeriesSettings) seriesSettings;
            applyScatterSeriesSettings(lineSeries, scatterSeriesSettings);
        }
    } else if (dataSeries instanceof IBarSeries) {
        /*
			 * Bar Series
			 */
        IBarSeries barSeries = (IBarSeries) dataSeries;
        IBarSeriesSettings barSeriesSettings = (IBarSeriesSettings) seriesSettings;
        applyBarSeriesSettings(barSeries, barSeriesSettings);
    }
}
Also used : ILineSeriesSettings(org.eclipse.swtchart.extensions.linecharts.ILineSeriesSettings) IBarSeriesSettings(org.eclipse.swtchart.extensions.barcharts.IBarSeriesSettings) IScatterSeriesSettings(org.eclipse.swtchart.extensions.scattercharts.IScatterSeriesSettings) IBarSeries(org.eclipse.swtchart.IBarSeries) ILineSeries(org.eclipse.swtchart.ILineSeries)

Aggregations

IBarSeries (org.eclipse.swtchart.IBarSeries)20 Color (org.eclipse.swt.graphics.Color)7 Chart (org.eclipse.swtchart.Chart)7 ILineSeries (org.eclipse.swtchart.ILineSeries)5 ISeries (org.eclipse.swtchart.ISeries)5 MouseEvent (org.eclipse.swt.events.MouseEvent)3 MouseMoveListener (org.eclipse.swt.events.MouseMoveListener)3 IAxis (org.eclipse.swtchart.IAxis)3 Rectangle (org.eclipse.swt.graphics.Rectangle)2 InteractiveChart (org.eclipse.swtchart.extensions.charts.InteractiveChart)2 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 IChartField (org.eclipse.linuxtools.dataviewers.charts.provider.IChartField)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GC (org.eclipse.swt.graphics.GC)1 Point (org.eclipse.swt.graphics.Point)1 RGB (org.eclipse.swt.graphics.RGB)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Control (org.eclipse.swt.widgets.Control)1 Event (org.eclipse.swt.widgets.Event)1