using JFreeChart with SWT and/or JFace

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ingo
Posts: 3
Joined: Thu Jul 07, 2005 10:46 am

using JFreeChart with SWT and/or JFace

Post by ingo » Thu Jul 07, 2005 10:54 am

hallo,

i'm using the ecplice-ide and develop with swt/jface. it is possible to using JFreeChart with swt/jface ?

thank's

mst
Posts: 3
Joined: Thu Jul 07, 2005 11:49 am

Post by mst » Thu Jul 07, 2005 11:53 am

I'm, into this problem to.
The bridge is to use SWT_AWT.
See below:

Code: Select all


protected void createContents() {
		shell = new Shell();
		shell.setSize(500, 375);
		shell.setText("SWT Application");

		final Composite drawarea = new Composite(shell, SWT.NONE);
		drawarea.setBounds(65, 65, 317, 192);
		Frame canvasFrame = SWT_AWT.new_Frame(drawarea);
		final java.awt.Canvas canvas = new java.awt.Canvas();
		canvasFrame.add(canvas);
		final java.awt.Graphics2D g2d = (java.awt.Graphics2D) canvas.getGraphics();
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,	RenderingHints.VALUE_ANTIALIAS_ON);

// and so on...		
		
	}

regards
mst

ingo
Posts: 3
Joined: Thu Jul 07, 2005 10:46 am

Post by ingo » Thu Jul 07, 2005 2:02 pm

exist a way WITHOUT awt ??

Code: Select all

protected Control createContents(Composite parent){
    TableColumn column;

    final Composite composite = new Composite(parent,SWT.EMBEDDED);
    composite.setLayout(new FillLayout());
    SashForm sash       = new SashForm(composite,SWT.VERTICAL); 
    Composite compChart = new Composite(sash,SWT.BORDER);

    // create chart-object for upper sash
    CategoryDataset dataset = createDataset();
    JFreeChart chart        = createChart(dataset);
    ChartPanel chartPanel   = new ChartPanel(chart, false);
    
    ??? add chart to compChart WITHOUT any awt-objects ???

    // create and fill tableviewer for lower sash
    viewer = new TableViewer(sash,SWT.BORDER|SWT.HORIZONTAL|SWT.VERTICAL);
    sash.setWeights(new int[]{60,40});

    Table table = viewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    ...
    return composite;
}
regards
ingo

Taqua
JFreeReport Project Leader
Posts: 698
Joined: Fri Mar 14, 2003 3:34 pm
Contact:

Post by Taqua » Thu Jul 07, 2005 3:16 pm

Hi,

JFreeChart is a standards compliant library and aims to be 100% Java. Support of non-standard (and non-superior) component systems does not offer anything valuable. The SWT is not faster than the AWT/Swing and is not platform independent.

JFreeChart relies on Java2D and will not work without that API. You have to use the bridge code offered by SWT if you want to use JFreeChart. There is no other way.

Have mo' fun,
said Thomas

ingo
Posts: 3
Joined: Thu Jul 07, 2005 10:46 am

Post by ingo » Tue Jul 12, 2005 3:09 pm

Hallo,

thanks for this information.

Ingo

Guest

Render to an image

Post by Guest » Mon Aug 01, 2005 3:47 pm

Actually, there is another way, which I just successfully prototyped a few minutes ago. Draw the chart to memory (as JPEG, PNG, etc) and then render an SWT image from the exported image in memory.

The code looks something like this:

Code: Select all

		Rectangle _size = ((Canvas) event.widget).getBounds();
		ByteArrayOutputStream outstream = new ByteArrayOutputStream();
		ChartUtilities.writeChartAsPNG(outstream, _chart, _size.width, _size.height);

		byte[] image_buffer = outstream.toByteArray();
		ByteArrayInputStream instream = new ByteArrayInputStream(image_buffer);
		ImageData image_data = new ImageData(instream);
		_image = new Image(event.display, image_data);
		event.gc.drawImage(_image, 0, 0);

Locked