Difference between revisions of "Data Visualization with Java"

From Self-Organization Wiki
Jump to: navigation, search
Line 104: Line 104:
 
       RefineryUtilities.centerFrameOnScreen(demo);
 
       RefineryUtilities.centerFrameOnScreen(demo);
 
       demo.setVisible(true);
 
       demo.setVisible(true);
 +
    }
 +
  }
 +
 +
which looks like this:
 +
 +
'''Screenshot'''
 +
 +
== PTPlot Library ==
 +
 +
* License Model: open source [http://ptolemy.eecs.berkeley.edu/ptIIcopyright.htm UC Berkeley copyright]
 +
* Webpage and download: [http://ptolemy.eecs.berkeley.edu/ptolemyII/index.htm]
 +
 +
Ptolemy II is a library that can be used for simulating different things either in real time or just static. It creates XY-LineCharts, BarCharts, Histogramms Live Plots.
 +
It is easy to work with it.
 +
 +
===Code Examples===
 +
 +
The follwing code snipped creates a non-static XY Diagramm
 +
 +
  import java.awt.event.WindowAdapter;
 +
  import java.awt.event.WindowEvent;
 +
  import javax.swing.JFrame;
 +
  import ptolemy.plot.PlotLive;
 +
  public class LivePlotTest extends PlotLive{
 +
    public LivePlotTest() {
 +
      //Set the range of the axes
 +
      setYRange(-1, 1);
 +
      setXRange(-1, 1);
 +
      //Set the amount of points on the screen
 +
      setPointsPersistence(500);
 +
      //Set the shape of the points, other possibilities are "points" or "dots"
 +
      setMarksStyle("dots");       
 +
    }
 +
    double i = 0;
 +
    public static void main(String[] args) {
 +
      //Create a plot
 +
      final LivePlotTest test = new LivePlotTest();
 +
      //Enable the exit button
 +
      JFrame frame = new JFrame("Test");
 +
      frame.addWindowListener(new WindowAdapter() {
 +
        public void windowClosing(WindowEvent event) {
 +
          test.stop();
 +
          System.exit(0);
 +
        }
 +
      });
 +
      //Make it visible
 +
      frame.add("Center", test);
 +
      frame.setVisible(true);
 +
      //Enable the start and the stop button
 +
      test.setButtons(true);
 +
      //Start the plot
 +
      test.start();
 +
      frame.pack();
 +
    }
 +
    //Create the points and add them to the plot
 +
    public void addPoints() {
 +
      addPoint(0, Math.sin(2*i),Math.cos(3*i), false);
 +
      i+=0.01;
 +
      try{
 +
        Thread.sleep(5);
 +
      }catch(InterruptedException ex){
 +
        ex.printStackTrace();
 +
      }
 
     }
 
     }
 
   }
 
   }

Revision as of 10:12, 5 July 2010

JChart2D Library

  • License Model: open source (LGPL license)
  • Webpage and download: [1]

The library is very easy to use because you don't have to spend a lot of time on making adjustments. You can create for example static line charts and dynamic line charts but you cannot create Pie Charts or Bar Charts.

Code Examples

The follwing code snipped creates a static XY Diagramm

 import info.monitorenter.gui.chart.Chart2D;
 import info.monitorenter.gui.chart.ITrace2D;
 import info.monitorenter.gui.chart.traces.Trace2DSimple;
 import javax.swing.JFrame;
 public class MinimalStaticChart {
 private MinimalStaticChart() {
   super();
 }
 public static void main(String[]args){
   // Create a chart:  
   Chart2D chart = new Chart2D();
   // Create an ITrace: 
   ITrace2D trace = new Trace2DSimple(); 
   // Add the trace to the chart: 
   chart.addTrace(trace); 
   // Create the Points and add them to the trace
   for(double i=0;i<=10;i+=0.001){
     trace.addPoint(Math.cos(3*i),Math.sin(4*i));
   }  
   // Create a frame.
   JFrame frame = new JFrame("MinimalStaticChart");
   // add the chart to the frame: 
   frame.getContentPane().add(chart);
   // make a few adjustments for the Frame
   frame.setSize(400,300);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setVisible(true);
   }
 }

which looks like this:

Screenshot

JFreeChart Library

  • License Model: Open Source (LGPL)
  • Webpage and download: [2]

JFreeChart is a useful package. You can create Line Charts, Bar Charts, Pie Charts and many more with it. There is a Developer Guide available for it. Using this Developer Guide working with JFreeChart is very easy.

Code Examples

The follwing code snipped creates a static XY Diagramm

 import java.awt.Color;
 import java.awt.Dimension;
 import javax.swing.JPanel;
 import org.jfree.chart.ChartFactory;
 import org.jfree.chart.ChartPanel;
 import org.jfree.chart.JFreeChart;
 import org.jfree.chart.plot.PlotOrientation;
 import org.jfree.data.xy.XYDataset;
 import org.jfree.data.xy.XYSeries;
 import org.jfree.data.xy.XYSeriesCollection;
 import org.jfree.ui.ApplicationFrame;
 import org.jfree.ui.RefineryUtilities;
 public class LineChartTest extends ApplicationFrame{	
   public LineChartTest(String title){
     super(title);
     XYDataset data = createDataset();
     JFreeChart chart = createChart(data);
     ChartPanel chartPanel = new ChartPanel(chart);
     chartPanel.setPreferredSize(new Dimension(500,270));
     setContentPane(chartPanel);
   }
   //Create Data	
   private static XYDataset createDataset(){
     //Create data series and add all the points
     XYSeries data1 = new XYSeries("Sin(t)");
     XYSeries data2 = new XYSeries("Cos(t)");
     for (int i=0;i<100;i++) {
       data1.add(i/10.0,Math.sin(i/10.0));
       data2.add(i/10.0,Math.cos(i/10.0));
     }	
     //Create a collection for the series and add them to the collection	  
     XYSeriesCollection dataset = new XYSeriesCollection();
     dataset.addSeries(data1);
     dataset.addSeries(data2);
     return dataset;
   }
   //Create a Chart with the XYDataset "data" and a few ettings
   private static JFreeChart createChart(XYDataset data){
     //Create a chart with the title "Sin/Cos", the xAxisLable "t", the yAxisLable "Value"
     JFreeChart chart = ChartFactory.createXYLineChart("Sin/Cos", "t", "Value", data, PlotOrientation.VERTICAL, true, false, false);
     chart.setBackgroundPaint(Color.white);
     chart.getPlot().setBackgroundPaint(Color.gray);
     return chart;
   }
   public static void main(String[] args) {
     LineChartTest demo = new LineChartTest("LineChartTest");
     demo.pack();
     RefineryUtilities.centerFrameOnScreen(demo);
     demo.setVisible(true);
   }
 }

which looks like this:

Screenshot

PTPlot Library

Ptolemy II is a library that can be used for simulating different things either in real time or just static. It creates XY-LineCharts, BarCharts, Histogramms Live Plots. It is easy to work with it.

Code Examples

The follwing code snipped creates a non-static XY Diagramm

 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import javax.swing.JFrame;
 import ptolemy.plot.PlotLive;
 public class LivePlotTest extends PlotLive{
   public LivePlotTest() {
     //Set the range of the axes
     setYRange(-1, 1);
     setXRange(-1, 1);
     //Set the amount of points on the screen
     setPointsPersistence(500);
     //Set the shape of the points, other possibilities are "points" or "dots"
     setMarksStyle("dots");        
   }
   double i = 0;
   public static void main(String[] args) {
     //Create a plot
     final LivePlotTest test = new LivePlotTest();
     //Enable the exit button
     JFrame frame = new JFrame("Test");
     frame.addWindowListener(new WindowAdapter() {
       public void windowClosing(WindowEvent event) {
         test.stop();
         System.exit(0);
       }
     });
     //Make it visible
     frame.add("Center", test);
     frame.setVisible(true);
     //Enable the start and the stop button
     test.setButtons(true);
     //Start the plot
     test.start();
     frame.pack();
   }
   //Create the points and add them to the plot
   public void addPoints() {
     addPoint(0, Math.sin(2*i),Math.cos(3*i), false);
     i+=0.01;
     try{
       Thread.sleep(5);		
     }catch(InterruptedException ex){
       ex.printStackTrace();
     }
   }
 }

which looks like this:

Screenshot

ExampleChart Library

  • License Model: open source (LGPL license)
  • Webpage and download: [4]

The library bla bla bla .....

Code Examples

The follwing code snipped creates a pie chart together with a life update Venn Diagramm

code

code code
code code? // comment
code code code !!

which looks like this:

Screenshot

Other Libraries

The following Java libraries looked promising, but turned out to be not recommendable:

  • M$$-Chart commercial license (500 € per license)
  • Crash-Chart beta version, still needs a lot of development, crashes frequently
  • Bad-Chart bad performance, missing important chart types like xy-Diagrams