Skip to content
Snippets Groups Projects
Commit 1e738625 authored by timmolter's avatar timmolter
Browse files

Issue #1: Let me pass a Collection of charts for a chart matrix plot

parent 567ef79e
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,8 @@ import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
......@@ -26,13 +28,12 @@ import javax.swing.JPanel;
import com.xeiam.xchart.Chart;
/**
* @author timmolter
*/
public class SwingWrapper {
private Chart[] charts;
private List<Chart> charts = new ArrayList<Chart>();
private int numRows;
private int numColumns;
......@@ -43,17 +44,31 @@ public class SwingWrapper {
*/
public SwingWrapper(Chart chart) {
this.charts = new Chart[1];
charts[0] = chart;
this.charts.add(chart);
}
/**
* Constructor
* Deprecated Constructor - use the one that takes a Collection! This will be removed in next version.
*
* @param charts
*/
@Deprecated
public SwingWrapper(Chart[] charts, int numRows, int numColumns) {
for (int i = 0; i < charts.length; i++) {
this.charts.add(charts[i]);
}
this.numRows = numRows;
this.numColumns = numColumns;
}
/**
* Constructor
*
* @param charts
*/
public SwingWrapper(List<Chart> charts, int numRows, int numColumns) {
this.charts = charts;
this.numRows = numRows;
this.numColumns = numColumns;
......@@ -76,7 +91,7 @@ public class SwingWrapper {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
JPanel chartPanel = new ChartJPanel(charts[0]);
JPanel chartPanel = new ChartJPanel(charts.get(0));
frame.getContentPane().add(chartPanel);
// Display the window.
......@@ -103,10 +118,9 @@ public class SwingWrapper {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new GridLayout(numRows, numColumns));
for (int i = 0; i < charts.length; i++) {
if (charts[i] != null) {
JPanel chartPanel = new ChartJPanel(charts[i]);
for (Chart chart : charts) {
if (chart != null) {
JPanel chartPanel = new ChartJPanel(chart);
frame.getContentPane().add(chartPanel);
} else {
JPanel chartPanel = new JPanel();
......
......@@ -15,6 +15,9 @@
*/
package com.xeiam.xchart.example;
import java.util.ArrayList;
import java.util.List;
import com.xeiam.xchart.Chart;
import com.xeiam.xchart.QuickChart;
import com.xeiam.xchart.swing.SwingWrapper;
......@@ -30,13 +33,12 @@ public class Example4 {
int numRows = 2;
int numCols = 2;
Chart[] charts = new Chart[numRows * numCols];
int chartCount = 0;
List<Chart> charts = new ArrayList<Chart>();
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
charts[chartCount++] = QuickChart.getChart(i + "," + j, "X", "Y", null, null, getRandomWalk(1000));
charts.add(QuickChart.getChart(i + "," + j, "X", "Y", null, null, getRandomWalk(1000)));
}
}
new SwingWrapper(charts, numRows, numCols).displayChartMatrix();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment