I use swtchart (http://www.swtchart.org/) and try to display it in the dialog but it is always failing.
SWT Dialog doesn't support swtchart, does it?
public final class TestDialog extends
Dialog {
private Chart chart;
private static double[] ySeries1 = {1,2,3,4,5,6,7,8,9,0};
public TestDialog(Shell shell) {
super(shell);
}
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
createChart(composite);
return composite;
}
static public Chart createChart(Composite parent) {
// create a chart
Chart chart = new Chart(parent, SWT.NONE);
// set titles
chart.getTitle().setText("Large Series");
chart.getAxisSet().getXAxis(0).getTitle().setText("Data Points");
chart.getAxisSet().getYAxis(0).getTitle().setText("Amplitude");
// create line series
ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE,
"line series");
lineSeries.setYSeries(ySeries1);
lineSeries.setSymbolSize(2);
// adjust the axis range
chart.getAxisSet().adjustRange();
return chart;
}
}
I don't think this issue is related to SWTChart, rather to your knowledge of SWT layouts.
Also, there's no reason for the chart to not work in a SWT dialog.
Please modify your overridden
createDialogArea
accordingly:Don't create your contents directly under
dialogArea
, rather create an intermediate container. I happen to know thatdialogArea
has aGridLayout
layout, hence I set theGridData
on the container.You may want to read this article very carefully.
Edit 1
So apparently, your chart is being drawn, but the dialog packs and you get the impression that it didn't draw. Try the code below, and resize the dialog to see the chart.
To fit the dialog to the chart is a whole different question (regarding SWT shells and layouts).