Menu

#20 plotArea.setBackgroundImage() doesn't work

v0.6.0
closed
nobody
swtchart (30)
5
2011-01-28
2010-02-07
Anonymous
No

Hello,
first of all: great framework!

I like to insert an image into the background of the chart's plotarea:

public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

Chart chart = new Chart(shell, SWT.NONE);
// the problem:
Composite plotArea = chart.getPlotArea();
plotArea.setBackgroundImage(new Image(null, "res/chart/bg-plotarea-kl.jpg"));//doesn't work!
// plotArea.setBackground(new Color(null,0,0,0)); //works fine

// other code...
final IAxis yAxis = chart.getAxisSet().getYAxis(0);
ILineSeries series = (ILineSeries)chart.getSeriesSet().createSeries(SeriesType.LINE, "line series");
double[] ySeries = { 0.0, 0.38, 0.71, 0.92, 1.0, 0.92, 0.71, 0.38, 0.0, -0.38, -0.71, -0.92, -1.0, -0.92,
-0.71, -0.38 };
series.setYSeries(ySeries);
chart.getAxisSet().adjustRange();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}

The setBackgroundImage()-method seems to do nothing, while setBackground() does work.

What's my mistake? Or is there any workaround?

Greetings
Philipp H.

Discussion

  • yoshitaka

    yoshitaka - 2010-02-10

    example code to draw a background image

     
  • yoshitaka

    yoshitaka - 2010-02-10

    Hi Philipp,

    Thanks for reporting a bug.

    When using SWT paint listener (org.eclipse.swt.events.PaintListener), the image painted with org.eclipse.swt.widgets.Control.setBackgroundImage(Image) will be overlaid and hidden. This is also the case for the plot area drawing a chart with SWT paint listener.

    Please find the attached code painting an image behind the series with using the feature #2945356 (the code is available in svn repository, but not yet released).

    Hope this helps.

    Best Regards,
    Yoshitaka

     
  • yoshitaka

    yoshitaka - 2011-01-28

    the feature #2945356 "custom paint listener" has been released in 0.7.0

     
  • yoshitaka

    yoshitaka - 2011-01-28
    • status: open --> closed