use of org.swtchart.ICustomPaintListener in project portfolio by buchen.
the class ReturnsVolatilityChartView method createBody.
@Override
protected Composite createBody(Composite parent) {
cache = make(DataSeriesCache.class);
Composite composite = new Composite(parent, SWT.NONE);
composite.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
resources = new LocalResourceManager(JFaceResources.getResources(), composite);
chart = new ScatterChart(composite);
chart.getTitle().setVisible(false);
IAxis xAxis = chart.getAxisSet().getXAxis(0);
xAxis.getTitle().setText(Messages.LabelVolatility);
// $NON-NLS-1$
xAxis.getTick().setFormat(new DecimalFormat("0.##%"));
IAxis yAxis = chart.getAxisSet().getYAxis(0);
yAxis.getTitle().setText(Messages.LabelPeformanceTTWROR);
// $NON-NLS-1$
yAxis.getTick().setFormat(new DecimalFormat("0.##%"));
((IPlotArea) chart.getPlotArea()).addCustomPaintListener(new ICustomPaintListener() {
@Override
public void paintControl(PaintEvent e) {
int y = xAxis.getPixelCoordinate(0);
e.gc.drawLine(y, 0, y, e.height);
int x = yAxis.getPixelCoordinate(0);
e.gc.drawLine(0, x, e.width, x);
}
@Override
public boolean drawBehindSeries() {
return true;
}
});
configurator = new DataSeriesConfigurator(this, DataSeries.UseCase.RETURN_VOLATILITY);
configurator.addListener(() -> updateChart());
DataSeriesChartLegend legend = new DataSeriesChartLegend(composite, configurator);
// $NON-NLS-1$ //$NON-NLS-2$
updateTitle(Messages.LabelHistoricalReturnsAndVolatiltity + " (" + configurator.getConfigurationName() + ")");
chart.getTitle().setText(getTitle());
GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 0).applyTo(composite);
GridDataFactory.fillDefaults().grab(true, true).applyTo(chart);
GridDataFactory.fillDefaults().grab(true, false).align(SWT.CENTER, SWT.FILL).applyTo(legend);
setChartSeries();
return composite;
}
use of org.swtchart.ICustomPaintListener in project netxms by netxms.
the class PlotArea method paintControl.
/*
* @see PaintListener#paintControl(PaintEvent)
*/
public void paintControl(PaintEvent e) {
Point p = getSize();
final GC gc = e.gc;
// draw the plot area background
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);
}
}
}
Aggregations