RCP with Dynamic Chart evaluation

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
rspan
Posts: 15
Joined: Wed May 02, 2007 4:36 pm

RCP with Dynamic Chart evaluation

Post by rspan » Wed May 02, 2007 4:48 pm

I am evaluating if we should use JFreeChart in our project. We need dynamic chart with Eclipse RCP. I am not sure how good for now JFreeChart support it. Based on information from this forum, it seems there are two ways to do it, one is SWT-AWT bridge and the other is SWT JFreeChart Support but it is in experimental phase. Could you please tell me

- Why SWT-AWT way is not good?
- What kind of situation now for the JFreeChart to support SWT with dynamic chart? Is it working properly already even in experiment? I see a thread regarding SWTMemoryUsage but it reported some bugs there and that thread moved to develoepr mailing list. So I have no idea what current stage regrarding this issue.
- Is there any developer guide on JFreeChart SWT support?
- Is there any demo source code for SWT with dynamich chart there?

Thanks,
Han

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: RCP with Dynamic Chart evaluation

Post by david.gilbert » Thu May 03, 2007 10:48 am

Until SWT includes "out-of-the-box" support for the Graphics2D API (if it ever does), I think JFreeChart will always be a second class citizen on SWT. We're trying out different ways to make JFreeChart useable in SWT, but it isn't the highest priority for me personally (I don't use SWT). Others are working on it though.
rspan wrote:- Why SWT-AWT way is not good?
I haven't tried it out. Some people have reported that it works well, others have said it has problems. I don't know enough about it to say any more.
rspan wrote:- What kind of situation now for the JFreeChart to support SWT with dynamic chart? Is it working properly already even in experiment? I see a thread regarding SWTMemoryUsage but it reported some bugs there and that thread moved to develoepr mailing list. So I have no idea what current stage regrarding this issue.
I've been busy on some other things, so I don't know exactly the current state. I don't recall running the SWTMemoryUsage demo - do you have a link to the thread?
rspan wrote:- Is there any developer guide on JFreeChart SWT support?
- Is there any demo source code for SWT with dynamich chart there?
No to both. The code is still experimental, so I haven't committed any time to documenting it.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

rspan
Posts: 15
Joined: Wed May 02, 2007 4:36 pm

Post by rspan » Fri May 04, 2007 4:10 am

David,

Here is link for the post about SWT and Dynamic chart. It seems finally it goes to developer mailing list. What is the final status? Is there any final working solution?

jfree.org/phpBB2/viewtopic.php?t=20763&start=0&postdays=0&postorder=asc&highlight=swt+memoryusage

Thanks,
Han

raghavan_26
Posts: 59
Joined: Fri Oct 13, 2006 11:35 am
Contact:

regarding dynamic plot in rcp

Post by raghavan_26 » Sat May 05, 2007 12:16 pm

Hi Rspan,

I am using the current experimental of swt-jfreechart version to diplay in RCP view .
It was working just similar to swing version .

In the current project i need to display that chart in an RCP view , It is working great .

With the SWT_AWT bridge the mouse events on the chart are not handled properly thats the reason we have eliminated to use SWT_AWT compatability and went for direct display in composite it self .


To the extent I have gone for my project Jfreechart-swt supports most of the features including dynamic plot also been able to diplay inside an RCP View.

by
raghavan

rspan
Posts: 15
Joined: Wed May 02, 2007 4:36 pm

Post by rspan » Tue May 08, 2007 4:44 pm

raghavan_26,

Thanks a lot for the valuable information. Could you please post some sample code regarding dynamic chart that is direct displayed in composite? I need to get a prototype running to evaluate the possiblity in our project. Thanks advance for your great help.

Thanks,
Han

raghavan_26
Posts: 59
Joined: Fri Oct 13, 2006 11:35 am
Contact:

example

Post by raghavan_26 » Thu May 10, 2007 5:04 am

the code example

Code: Select all

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.experimental.chart.swt.ChartComposite;
import org.jfree.ui.RectangleInsets;

public class SWTMemoryUsageDemo {

   private static Display display;
   private static ChartComposite chartComposite;
   
   private TimeSeries total;
   private TimeSeries free;

   class DataGenerator extends Timer implements ActionListener {
      DataGenerator(int i) {
         super(i, null);
         addActionListener(this);
      }
      
      public void actionPerformed(ActionEvent actionevent) {
         //  for SWT UI thread issue, use Display.asyncExec()
         display.asyncExec(new Runnable() {
            public void run() {
               long l = Runtime.getRuntime().freeMemory();
               long l1 = Runtime.getRuntime().totalMemory();
               addTotalObservation(l1);
               addFreeObservation(l);
               
               //  for chart redraw, use ChartComposite.forceRedraw();
               //         if not use this, then chart will not redraw.
               //         I don't know why.
               chartComposite.forceRedraw();
               }
         });
      }
   }
   
   public SWTMemoryUsageDemo(int i) {
      total = new TimeSeries("Total Memory", org.jfree.data.time.Millisecond.class);
      total.setMaximumItemAge(i);
      free = new TimeSeries("Free Memory", org.jfree.data.time.Millisecond.class);
      free.setMaximumItemAge(i);
   }
   
   public JFreeChart createChart() {
      TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
      timeseriescollection.addSeries(total);
      timeseriescollection.addSeries(free);
      
      DateAxis dateaxis = new DateAxis("Time");
      NumberAxis numberaxis = new NumberAxis("Memory");
      dateaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
      numberaxis.setTickLabelFont(new Font("SansSerif", 0, 12));
      dateaxis.setLabelFont(new Font("SansSerif", 0, 14));
      numberaxis.setLabelFont(new Font("SansSerif", 0, 14));
      
      XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(true, false);
      xylineandshaperenderer.setSeriesPaint(0, Color.red);
      xylineandshaperenderer.setSeriesPaint(1, Color.green);
      xylineandshaperenderer.setStroke(new BasicStroke(3F, 0, 2));
      
      XYPlot xyplot = new XYPlot(timeseriescollection, dateaxis, numberaxis, xylineandshaperenderer);
      xyplot.setBackgroundPaint(Color.lightGray);
      xyplot.setDomainGridlinePaint(Color.white);
      xyplot.setRangeGridlinePaint(Color.white);
      xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
      
      dateaxis.setAutoRange(true);
      dateaxis.setLowerMargin(0.0D);
      dateaxis.setUpperMargin(0.0D);
      dateaxis.setTickLabelsVisible(true);
      numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
      
      JFreeChart jfreechart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", 1, 24), xyplot, true);
      jfreechart.setBackgroundPaint(Color.white);
      
      return jfreechart;
   }

   private void addTotalObservation(final double d) {
      total.addOrUpdate(new Millisecond(), d);
   }

   private void addFreeObservation(final double d) {
      free.addOrUpdate(new Millisecond(), d);
   }

   public static void main(String args[]) {
      display = new Display();
      Shell shell = new Shell(display);
      shell.setSize(600, 300);
      shell.setLayout(new FillLayout());
      shell.setText("Memory Usage Demo");

      SWTMemoryUsageDemo memoryusagedemo = new SWTMemoryUsageDemo(30000);
      JFreeChart chart = memoryusagedemo.createChart();

      chartComposite = new ChartComposite(shell, SWT.NONE, chart, true);
      chartComposite.setDisplayToolTips(true);
      chartComposite.setHorizontalAxisTrace(false);
      chartComposite.setVerticalAxisTrace(false);
      shell.open();
      
      (memoryusagedemo.new DataGenerator(100)).start();
      
      while (!shell.isDisposed()) {
         if (!display.readAndDispatch())
            display.sleep();
         
      }
   }
} 
use the chart composite class of jfreechart-swt version to get the display .

rspan
Posts: 15
Joined: Wed May 02, 2007 4:36 pm

Post by rspan » Thu May 10, 2007 5:28 pm

Thanks. raghavan_26 for the sample. Especially your notes on how to get display. That is very improtant bucase I need to get the display from the view.

Did you go the same problem which Silent mention, basically running for amount of time, out of handler exception happens or if resize the windows, then happend Exception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Widget is disposed. How do you fix that?

Thanks.

raghavan_26
Posts: 59
Joined: Fri Oct 13, 2006 11:35 am
Contact:

Post by raghavan_26 » Fri May 11, 2007 6:32 am

hi ,

I ran that class for a number of time , Ist time I was running i was able to get SWTException , then again I ran it a noer of times and even maximized and minimized the chart composite I dint get any exception what u were talking of "AWT-EventQueue-0" exception .


But the only problem I get using that class is even though I close the composite the process is still running in memory. so I had to terminate it exclusively .

rspan
Posts: 15
Joined: Wed May 02, 2007 4:36 pm

Post by rspan » Tue May 15, 2007 7:02 pm

Actually this exception only happens when the application running amout of time. It seems to me the Native SWT way is not a good choice for dynamic chart.

Locked