Difference between revisions of "Data Visualization with Java"
(→Code Examples) |
|||
Line 37: | Line 37: | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.setVisible(true); | frame.setVisible(true); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | which looks like this: | ||
+ | |||
+ | '''Screenshot''' | ||
+ | |||
+ | == JFreeChart Library == | ||
+ | |||
+ | * License Model: Open Source (LGPL) | ||
+ | * Webpage and download: [http://www.jfree.org/jfreechart/] | ||
+ | |||
+ | 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); | ||
} | } | ||
} | } |
Revision as of 09:10, 5 July 2010
Contents
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
ExampleChart Library
- License Model: open source (LGPL license)
- Webpage and download: [3]
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