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();
}
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);
}
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();
}
}
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;
}
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;
}
Aggregations