use of org.eclipse.swtchart.ISeries in project swtchart by eclipse.
the class CustomPaintListenerExample 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("Custom Paint Listener");
ISeries lineSeries = chart.getSeriesSet().createSeries(SeriesType.LINE, "line series");
lineSeries.setYSeries(ySeries);
// add paint listeners
IPlotArea plotArea = (IPlotArea) chart.getPlotArea();
plotArea.addCustomPaintListener(new FrontPaintListener());
plotArea.addCustomPaintListener(new BehindPaintListener());
// adjust the axis range
chart.getAxisSet().adjustRange();
return chart;
}
use of org.eclipse.swtchart.ISeries 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;
}
use of org.eclipse.swtchart.ISeries in project swtchart by eclipse.
the class SymbolBoundsExample 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("Symbol Bounds");
// create line series
ILineSeries series1 = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "series 1");
series1.setYSeries(ySeries1);
ILineSeries series2 = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, "series 2");
series2.setYSeries(ySeries2);
series2.setLineColor(Display.getDefault().getSystemColor(SWT.COLOR_RED));
// adjust the axis range
chart.getAxisSet().adjustRange();
// add mouse move listener to open tooltip on data point
chart.getPlotArea().addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
for (ISeries series : chart.getSeriesSet().getSeries()) {
for (int i = 0; i < series.getYSeries().length; i++) {
Point p = series.getPixelCoordinates(i);
double distance = Math.sqrt(Math.pow(e.x - p.x, 2) + Math.pow(e.y - p.y, 2));
if (distance < ((ILineSeries) series).getSymbolSize()) {
setToolTipText(series, i);
return;
}
}
}
chart.getPlotArea().setToolTipText(null);
}
private void setToolTipText(ISeries series, int index) {
chart.getPlotArea().setToolTipText("Series: " + series.getId() + "\nValue: " + series.getYSeries()[index]);
}
});
return chart;
}
use of org.eclipse.swtchart.ISeries in project swtchart by eclipse.
the class ErrorBarsExample 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("Error Bars");
// create series
ISeries series = chart.getSeriesSet().createSeries(SeriesType.LINE, "line series");
series.setYSeries(ySeries);
// set error bars
IErrorBar errorBar = series.getYErrorBar();
errorBar.setVisible(true);
errorBar.setError(0.1);
// adjust the axis range
chart.getAxisSet().adjustRange();
return chart;
}
use of org.eclipse.swtchart.ISeries in project swtchart by eclipse.
the class ScrollableChart method createSeries.
@Override
public ISeries createSeries(ISeriesData seriesData, ISeriesSettings seriesSettings) throws SeriesException {
ISeries series = baseChart.createSeries(seriesData, seriesSettings);
resetSlider();
return series;
}
Aggregations