Search in sources :

Example 1 with IAxis

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

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

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

the class ScrollableChart method addPrimaryAxisY.

private void addPrimaryAxisY(IChartSettings chartSettings) {
    IAxisSet axisSet = baseChart.getAxisSet();
    IAxis yAxisPrimary = axisSet.getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
    IPrimaryAxisSettings primaryAxisSettings = chartSettings.getPrimaryAxisSettingsY();
    setAxisSettings(yAxisPrimary, primaryAxisSettings);
    baseChart.putYAxisSettings(BaseChart.ID_PRIMARY_Y_AXIS, primaryAxisSettings);
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) IAxis(org.eclipse.swtchart.IAxis)

Example 4 with IAxis

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

the class ScrollableChart method addSecondaryAxesY.

private void addSecondaryAxesY(IChartSettings chartSettings) {
    IAxisSet axisSet = baseChart.getAxisSet();
    for (int id : axisSet.getYAxisIds()) {
        if (id != BaseChart.ID_PRIMARY_Y_AXIS) {
            axisSet.deleteYAxis(id);
        }
    }
    /*
		 * Remove all items except the primary axis settings.
		 */
    baseChart.removeYAxisSettings();
    /*
		 * Add the axis settings.
		 */
    for (ISecondaryAxisSettings secondaryAxisSettings : chartSettings.getSecondaryAxisSettingsListY()) {
        int yAxisId = axisSet.createYAxis();
        IAxis yAxisSecondary = axisSet.getYAxis(yAxisId);
        setAxisSettings(yAxisSecondary, secondaryAxisSettings);
        baseChart.putYAxisSettings(yAxisId, secondaryAxisSettings);
    }
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) Point(org.eclipse.swt.graphics.Point) IAxis(org.eclipse.swtchart.IAxis)

Example 5 with IAxis

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

the class AbstractExtendedChart method setRange.

@Override
public void setRange(String axis, double start, double stop) {
    IAxisSet axisSet = getAxisSet();
    IAxis selectedAxis = (axis.equals(IExtendedChart.X_AXIS)) ? axisSet.getXAxis(BaseChart.ID_PRIMARY_X_AXIS) : axisSet.getYAxis(BaseChart.ID_PRIMARY_Y_AXIS);
    setRange(selectedAxis, start, stop, true);
}
Also used : IAxisSet(org.eclipse.swtchart.IAxisSet) 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