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