Search in sources :

Example 41 with IAxis

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

the class InteractiveChart method handleMouseUpEvent.

/**
 * Handles the mouse up event.
 *
 * @param event
 *            the mouse up event
 */
private void handleMouseUpEvent(Event event) {
    if (event.button == 1 && System.currentTimeMillis() - clickedTime > 100) {
        for (IAxis axis : getAxisSet().getAxes()) {
            Point range = null;
            if ((getOrientation() == SWT.HORIZONTAL && axis.getDirection() == Direction.X) || (getOrientation() == SWT.VERTICAL && axis.getDirection() == Direction.Y)) {
                range = selection.getHorizontalRange();
            } else {
                range = selection.getVerticalRange();
            }
            if (range != null && range.x != range.y) {
                setRange(range, axis);
            }
        }
    }
    selection.dispose();
    redraw();
}
Also used : Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis)

Example 42 with IAxis

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

the class PlotArea method paintControl.

/*
	 * @see PaintListener#paintControl(PaintEvent)
	 */
public void paintControl(PaintEvent e) {
    Point p = getSize();
    GC gc = e.gc;
    // draw the plot area background
    Color oldBackground = gc.getBackground();
    gc.setBackground(getBackground());
    gc.fillRectangle(0, 0, p.x, p.y);
    // draw grid
    for (IAxis axis : chart.getAxisSet().getAxes()) {
        ((Grid) axis.getGrid()).draw(gc, p.x, p.y);
    }
    // draw behind series
    for (ICustomPaintListener listener : paintListeners) {
        if (listener.drawBehindSeries()) {
            listener.paintControl(e);
        }
    }
    // draw series. The line series should be drawn on bar series.
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        if (series instanceof IBarSeries) {
            ((Series) series).draw(gc, p.x, p.y);
        }
    }
    for (ISeries series : chart.getSeriesSet().getSeries()) {
        if (series instanceof ILineSeries) {
            ((Series) series).draw(gc, p.x, p.y);
        }
    }
    // draw over series
    for (ICustomPaintListener listener : paintListeners) {
        if (!listener.drawBehindSeries()) {
            listener.paintControl(e);
        }
    }
    e.gc.setBackground(oldBackground);
}
Also used : IBarSeries(org.eclipse.swtchart.IBarSeries) ILineSeries(org.eclipse.swtchart.ILineSeries) ISeries(org.eclipse.swtchart.ISeries) Series(org.eclipse.swtchart.internal.series.Series) ICustomPaintListener(org.eclipse.swtchart.ICustomPaintListener) IBarSeries(org.eclipse.swtchart.IBarSeries) Color(org.eclipse.swt.graphics.Color) ILineSeries(org.eclipse.swtchart.ILineSeries) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) ISeries(org.eclipse.swtchart.ISeries) IAxis(org.eclipse.swtchart.IAxis)

Example 43 with IAxis

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

the class ChartLayout method adjustForMostLeftRightTickLabel.

/**
 * Adjust the axis size for most left/right tick label.
 *
 * @param r
 *            the rectangle to layout
 */
private void adjustForMostLeftRightTickLabel(Rectangle r) {
    // get axis margin hint
    int rightAxisMarginHint = 0;
    int leftAxisMarginHint = 0;
    for (IAxis axis : horizontalAxes) {
        if (!axis.getTick().isVisible()) {
            continue;
        }
        rightAxisMarginHint = Math.max(rightAxisMarginHint, ((Axis) axis).getTick().getAxisTickLabels().getRightMarginHint(plotAreaWidth));
        leftAxisMarginHint = Math.max(leftAxisMarginHint, ((Axis) axis).getTick().getAxisTickLabels().getLeftMarginHint(plotAreaWidth));
    }
    // have space to draw most right tick label on horizontal axis
    if ((legendWidth == 0 || legend.getPosition() != SWT.RIGHT) && rightAxisWidth < rightAxisMarginHint) {
        rightAxisWidth = rightAxisMarginHint;
        computePlotAreaSize(r);
        updateHorizontalAxisTick();
    }
    // have space to draw most left tick label on horizontal axis
    if ((legendWidth == 0 || legend.getPosition() != SWT.LEFT) && leftAxisWidth < leftAxisMarginHint) {
        leftAxisWidth = leftAxisMarginHint;
        computePlotAreaSize(r);
        updateHorizontalAxisTick();
    }
}
Also used : Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis) IAxis(org.eclipse.swtchart.IAxis) Axis(org.eclipse.swtchart.internal.axis.Axis)

Example 44 with IAxis

use of org.eclipse.swtchart.IAxis 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 45 with IAxis

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

the class PxielToDataConversionExample 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("Pxiel To Data Conversion");
    // get axes
    final IAxis xAxis = chart.getAxisSet().getXAxis(0);
    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 mouse move listener to show mouse position on tooltip
    chart.getPlotArea().addMouseMoveListener(new MouseMoveListener() {

        public void mouseMove(MouseEvent e) {
            double x = xAxis.getDataCoordinate(e.x);
            double y = yAxis.getDataCoordinate(e.y);
            chart.getPlotArea().setToolTipText("x:" + x + ", y:" + y);
        }
    });
    return chart;
}
Also used : MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) MouseEvent(org.eclipse.swt.events.MouseEvent) ILineSeries(org.eclipse.swtchart.ILineSeries) Chart(org.eclipse.swtchart.Chart) IAxis(org.eclipse.swtchart.IAxis)

Aggregations

IAxis (org.eclipse.swtchart.IAxis)64 Point (org.eclipse.swt.graphics.Point)27 Range (org.eclipse.swtchart.Range)19 IAxisSet (org.eclipse.swtchart.IAxisSet)10 Chart (org.eclipse.swtchart.Chart)7 ISeries (org.eclipse.swtchart.ISeries)7 MouseEvent (org.eclipse.swt.events.MouseEvent)5 ILineSeries (org.eclipse.swtchart.ILineSeries)5 Color (org.eclipse.swt.graphics.Color)4 GridData (org.eclipse.swt.layout.GridData)4 DecimalFormat (java.text.DecimalFormat)3 PaintEvent (org.eclipse.swt.events.PaintEvent)3 PaintListener (org.eclipse.swt.events.PaintListener)3 GC (org.eclipse.swt.graphics.GC)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Composite (org.eclipse.swt.widgets.Composite)3 IBarSeries (org.eclipse.swtchart.IBarSeries)3 ITitle (org.eclipse.swtchart.ITitle)3 Axis (org.eclipse.swtchart.internal.axis.Axis)3 StyleRange (org.eclipse.swt.custom.StyleRange)2