diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/demo/ChartDemo.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/ChartDemo.java new file mode 100644 index 0000000000000000000000000000000000000000..5a050a8ddd2015ea466d835b781943057f123275 --- /dev/null +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/ChartDemo.java @@ -0,0 +1,193 @@ +/** + * Copyright (c) 2011-2013 Xeiam LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.xeiam.xchart.demo; + +import java.awt.Dimension; +import java.awt.GridLayout; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JSplitPane; +import javax.swing.JTree; +import javax.swing.event.TreeSelectionEvent; +import javax.swing.event.TreeSelectionListener; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.TreeSelectionModel; + +import com.xeiam.xchart.XChartPanel; +import com.xeiam.xchart.demo.charts.Example10; +import com.xeiam.xchart.demo.charts.Example11; +import com.xeiam.xchart.demo.charts.Example2; +import com.xeiam.xchart.demo.charts.Example3; +import com.xeiam.xchart.demo.charts.Example5; +import com.xeiam.xchart.demo.charts.Example6; +import com.xeiam.xchart.demo.charts.Example7; +import com.xeiam.xchart.demo.charts.Example8; +import com.xeiam.xchart.demo.charts.Example9; + +/** + * Class containing all XChart example charts + * + * @author timmolter + */ +public class ChartDemo extends JPanel implements TreeSelectionListener { + + /** The main split frame */ + private JSplitPane splitPane; + + /** The tree */ + private JTree tree; + + /** The panel for chart */ + private JPanel chartPanel; + + /** + * Constructor + */ + public ChartDemo() { + + super(new GridLayout(1, 0)); + + // Create the nodes. + DefaultMutableTreeNode top = new DefaultMutableTreeNode("XChart Example Charts"); + createNodes(top); + + // Create a tree that allows one selection at a time. + tree = new JTree(top); + tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + + // Listen for when the selection changes. + tree.addTreeSelectionListener(this); + + // Create the scroll pane and add the tree to it. + JScrollPane treeView = new JScrollPane(tree); + + // Create Chart Panel + chartPanel = new XChartPanel(new Example10().getChart()); + + // Add the scroll panes to a split pane. + splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); + splitPane.setTopComponent(treeView); + splitPane.setBottomComponent(chartPanel); + + Dimension minimumSize = new Dimension(100, 125); + treeView.setMinimumSize(minimumSize); + splitPane.setDividerLocation(100); + splitPane.setPreferredSize(new Dimension(800, 800)); + + // Add the split pane to this panel. + add(splitPane); + } + + @Override + public void valueChanged(TreeSelectionEvent e) { + + DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); + + if (node == null) { + return; + } + + Object nodeInfo = node.getUserObject(); + // tree leaf + if (node.isLeaf()) { + ChartInfo chartInfo = (ChartInfo) nodeInfo; + // displayURL(chartInfo.bookURL); + chartPanel = new XChartPanel(chartInfo.getExampleChart()); + splitPane.setBottomComponent(chartPanel); + } + // tree branch node + else { + // do nothing + } + } + + private void createNodes(DefaultMutableTreeNode top) { + + // categories + DefaultMutableTreeNode category = null; + // leaves + DefaultMutableTreeNode chart = null; + + // First category + category = new DefaultMutableTreeNode("Line Charts"); + top.add(category); + + chart = new DefaultMutableTreeNode(new ChartInfo("Example10", new Example10().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("Example11", new Example11().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("Example2", new Example2().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("Example3", new Example3().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("Example5", new Example5().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("Example6", new Example6().getChart())); + category.add(chart); + + // Second category + category = new DefaultMutableTreeNode("Other Charts"); + top.add(category); + + chart = new DefaultMutableTreeNode(new ChartInfo("Example7", new Example7().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("Example8", new Example8().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("Example9", new Example9().getChart())); + category.add(chart); + + } + + /** + * Create the GUI and show it. For thread safety, this method should be invoked from the event dispatch thread. + */ + private static void createAndShowGUI() { + + // Create and set up the window. + JFrame frame = new JFrame("XChart Demo"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + // Add content to the window. + frame.add(new ChartDemo()); + + // Display the window. + frame.pack(); + frame.setVisible(true); + } + + public static void main(String[] args) { + + // Schedule a job for the event dispatch thread: + // creating and showing this application's GUI. + javax.swing.SwingUtilities.invokeLater(new Runnable() { + + @Override + public void run() { + + createAndShowGUI(); + } + }); + } +} diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/demo/ChartInfo.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/ChartInfo.java new file mode 100644 index 0000000000000000000000000000000000000000..99991626572fe462d8048c0420df37ea2711fa4e --- /dev/null +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/ChartInfo.java @@ -0,0 +1,62 @@ +/** + * Copyright (C) 2013 Xeiam LLC http://xeiam.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.xeiam.xchart.demo; + +import com.xeiam.xchart.Chart; + +/** + * @author timmolter + */ +public final class ChartInfo { + + private final String exampleChartName; + private final Chart exampleChart; + + /** + * Constructor + * + * @param exampleChartName + * @param exampleChart + */ + public ChartInfo(String exampleChartName, Chart exampleChart) { + + this.exampleChartName = exampleChartName; + this.exampleChart = exampleChart; + } + + public String getExampleChartName() { + + return exampleChartName; + } + + public Chart getExampleChart() { + + return exampleChart; + } + + @Override + public String toString() { + + return this.exampleChartName; + } + +} diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example10.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example10.java similarity index 96% rename from xchart-examples/src/main/java/com/xeiam/xchart/example/Example10.java rename to xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example10.java index f4e7ab5267fc03bb976fff1b93067ccb223d8f4a..127cf87aa162e12d67ca0745d6b7d4e3f3a732d3 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example10.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example10.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.demo.charts; import java.util.Arrays; import java.util.Collection; @@ -28,10 +28,18 @@ import com.xeiam.xchart.SwingWrapper; * * @author timmolter */ -public class Example10 { +public class Example10 implements ExampleChart { public static void main(String[] args) { + ExampleChart exampleChart = new Example10(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + // data Number[] xDataArray = new Number[] { 0.0, 0.03139525976465669, 0.06266661678215213, 0.0936906572928623, 0.1243449435824274, 0.1545084971874737, 0.184062276342339, 0.21288964578253636, 0.24087683705085766, 0.26791339748949833, 0.29389262614623657, 0.3187119948743448, 0.34227355296434425, 0.3644843137107057, 0.38525662138789457, 0.4045084971874737, 0.42216396275100754, @@ -73,6 +81,6 @@ public class Example10 { Series series1 = chart.addSeries("data", xData, yData); series1.setMarker(SeriesMarker.NONE); - new SwingWrapper(chart).displayChart(); + return chart; } } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example11.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example11.java similarity index 97% rename from xchart-examples/src/main/java/com/xeiam/xchart/example/Example11.java rename to xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example11.java index 10430447c77e104458b93a808201c5a319290f42..731d97c9a3561529da9cb804a0987f5e3362cf70 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example11.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example11.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.demo.charts; import java.util.Arrays; import java.util.Collection; @@ -28,10 +28,18 @@ import com.xeiam.xchart.SwingWrapper; * * @author timmolter */ -public class Example11 { +public class Example11 implements ExampleChart { public static void main(String[] args) { + ExampleChart exampleChart = new Example11(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + // data Number[] xDataArray = new Number[] { 0.0, 2.0E-6, 4.0E-6, 6.0E-6, 8.0E-6, 9.999999999999999E-6, 1.1999999999999999E-5, 1.3999999999999998E-5, 1.6E-5, 1.8E-5, 2.0E-5, 2.2000000000000003E-5, 2.4000000000000004E-5, 2.6000000000000005E-5, 2.8000000000000006E-5, 3.0000000000000008E-5, 3.2000000000000005E-5, 3.4000000000000007E-5, 3.600000000000001E-5, 3.800000000000001E-5, @@ -88,6 +96,6 @@ public class Example11 { Series series1 = chart.addSeries("data", xData, yData); series1.setMarker(SeriesMarker.NONE); - new SwingWrapper(chart).displayChart(); + return chart; } } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example2.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example2.java similarity index 86% rename from xchart-examples/src/main/java/com/xeiam/xchart/example/Example2.java rename to xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example2.java index c2009ff628d244d66109798844655cb645517273..efc17178c852b9269ffaf1995c8706d2623e4c9e 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example2.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example2.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.demo.charts; import java.util.ArrayList; import java.util.Collection; @@ -30,10 +30,18 @@ import com.xeiam.xchart.SwingWrapper; * * @author timmolter */ -public class Example2 { +public class Example2 implements ExampleChart { public static void main(String[] args) { + ExampleChart exampleChart = new Example10(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + // generates sine data int size = 30; Collection<Number> xData1 = new ArrayList<Number>(); @@ -45,7 +53,7 @@ public class Example2 { } // Create Chart - Chart chart = new Chart(440, 300); + Chart chart = new Chart(800, 600); // Customize Chart chart.setTitleVisible(false); @@ -58,7 +66,7 @@ public class Example2 { series1.setMarkerColor(SeriesColor.GREEN); series1.setMarker(SeriesMarker.SQUARE); - new SwingWrapper(chart).displayChart(); + return chart; } } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example3.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example3.java similarity index 84% rename from xchart-examples/src/main/java/com/xeiam/xchart/example/Example3.java rename to xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example3.java index b57c080cdf38729acf3692710b4177f101ac2d36..2925f387a3fdbef6ac11541956da3f6a78215682 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example3.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example3.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.demo.charts; import java.util.ArrayList; import java.util.Collection; @@ -26,12 +26,20 @@ import com.xeiam.xchart.SwingWrapper; * * @author timmolter */ -public class Example3 { +public class Example3 implements ExampleChart { public static void main(String[] args) { + ExampleChart exampleChart = new Example10(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + // Create Chart - Chart chart = new Chart(700, 500); + Chart chart = new Chart(800, 600); for (int i = 1; i <= 14; i++) { @@ -53,7 +61,6 @@ public class Example3 { chart.addSeries(seriesName, xData, yData); } - // JFrame testFrame = new TestFrame(chart); - new SwingWrapper(chart).displayChart(); + return chart; } } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example5.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example5.java similarity index 80% rename from xchart-examples/src/main/java/com/xeiam/xchart/example/Example5.java rename to xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example5.java index 46808f16c3656aeda3ce762467119ee58edc4174..99c829cd445ad6877204d78600f2678792737b2b 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example5.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example5.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.demo.charts; import com.xeiam.xchart.Chart; import com.xeiam.xchart.SwingWrapper; @@ -23,12 +23,20 @@ import com.xeiam.xchart.SwingWrapper; * * @author timmolter */ -public class Example5 { +public class Example5 implements ExampleChart { public static void main(String[] args) { + ExampleChart exampleChart = new Example10(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + // Create Chart - Chart chart = new Chart(700, 500); + Chart chart = new Chart(800, 600); // Customize Chart chart.setTitle("Sample Chart"); @@ -38,7 +46,7 @@ public class Example5 { chart.addSeries("vertical", new double[] { 1, 1 }, new double[] { -10, 10 }); chart.addSeries("horizontal", new double[] { -10, 10 }, new double[] { 0, 0 }); - new SwingWrapper(chart).displayChart(); + return chart; } } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example6.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example6.java similarity index 79% rename from xchart-examples/src/main/java/com/xeiam/xchart/example/Example6.java rename to xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example6.java index b4238270caa7bd1bf516bd90b2154c94966782b2..2b0720e5f95df9063c7131da49bbe1f66b4453cb 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example6.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example6.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.demo.charts; import com.xeiam.xchart.Chart; import com.xeiam.xchart.SwingWrapper; @@ -23,12 +23,20 @@ import com.xeiam.xchart.SwingWrapper; * * @author timmolter */ -public class Example6 { +public class Example6 implements ExampleChart { public static void main(String[] args) { + ExampleChart exampleChart = new Example10(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + // Create Chart - Chart chart = new Chart(700, 500); + Chart chart = new Chart(800, 600); // Customize Chart chart.setTitle("Sample Chart"); @@ -37,7 +45,7 @@ public class Example6 { chart.addSeries("single point (1,1)", new double[] { 1 }, new double[] { 1 }); - new SwingWrapper(chart).displayChart(); + return chart; } } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example7.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example7.java similarity index 80% rename from xchart-examples/src/main/java/com/xeiam/xchart/example/Example7.java rename to xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example7.java index 82a716d7b532725735448cc97336afa8f735d0e0..0d10a6b6f8d2e8bf7ef1b981b0d539ebe9811a9a 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example7.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example7.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.demo.charts; import java.util.Arrays; import java.util.Collection; @@ -26,22 +26,29 @@ import com.xeiam.xchart.SwingWrapper; * * @author timmolter */ -public class Example7 { +public class Example7 implements ExampleChart { - public static void main(String[] args) throws Exception { + public static void main(String[] args) { + + ExampleChart exampleChart = new Example10(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { Collection<Number> xData = Arrays.asList(new Number[] { 12228120L, 12228984L, 12229848L, 12230712L, 12231576L, 12232440L, 12233304L, 12234168L, 12235032L, 12235896L }); Collection<Number> yData = Arrays.asList(new Number[] { 0.0, 1.0, 2.0, 0.0, 1.0, 2.0, 0.0, 1.0, 2.0, 0.0 }); // Create Chart - Chart chart = new Chart(700, 500); + Chart chart = new Chart(800, 600); chart.setTitle("Sample Chart"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.addSeries("y(x)", xData, yData); - new SwingWrapper(chart).displayChart(); - + return chart; } } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example8.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example8.java similarity index 86% rename from xchart-examples/src/main/java/com/xeiam/xchart/example/Example8.java rename to xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example8.java index 7e773e3a41fa144ba6c18af23a29ab4f5908ecd8..453787e705fce6b983399c6f8d789795dad65bb9 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example8.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example8.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.demo.charts; import java.util.ArrayList; import java.util.Collection; @@ -30,10 +30,18 @@ import com.xeiam.xchart.SwingWrapper; * * @author timmolter */ -public class Example8 { +public class Example8 implements ExampleChart { public static void main(String[] args) { + ExampleChart exampleChart = new Example10(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { + // generates data int size = 10; Collection<Number> xData1 = new ArrayList<Number>(); @@ -46,7 +54,7 @@ public class Example8 { } // Create Chart - Chart chart = new Chart(600, 400); + Chart chart = new Chart(800, 600); // Customize Chart chart.setTitleVisible(false); @@ -60,7 +68,7 @@ public class Example8 { series1.setMarkerColor(SeriesColor.GREEN); series1.setMarker(SeriesMarker.SQUARE); - new SwingWrapper(chart).displayChart(); + return chart; } } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example9.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example9.java similarity index 85% rename from xchart-examples/src/main/java/com/xeiam/xchart/example/Example9.java rename to xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example9.java index 5fee0c9ae7758ed0559045691dee773544a50e58..cc42e1e0d39f89ad19f1472a85aa1124be373e3e 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example9.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example9.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.example; +package com.xeiam.xchart.demo.charts; import java.awt.Color; import java.awt.Font; @@ -38,20 +38,34 @@ import com.xeiam.xchart.SwingWrapper; * * @author timmolter */ -public class Example9 { +public class Example9 implements ExampleChart { - public static void main(String[] args) throws ParseException { + public static void main(String[] args) { + + ExampleChart exampleChart = new Example9(); + Chart chart = exampleChart.getChart(); + new SwingWrapper(chart).displayChart(); + } + + @Override + public Chart getChart() { // Create Chart - Chart chart = new Chart(700, 500); + Chart chart = new Chart(800, 600); // generates linear data Collection<Date> xData = new ArrayList<Date>(); Collection<Number> yData = new ArrayList<Number>(); DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); + Date date = null; for (int i = 1; i <= 10; i++) { - Date date = sdf.parse(i + ".10.2008"); + + try { + date = sdf.parse(i + ".10.2008"); + } catch (ParseException e) { + e.printStackTrace(); + } xData.add(date); yData.add(Math.random() * i); } @@ -81,7 +95,7 @@ public class Example9 { series.setMarker(SeriesMarker.CIRCLE); series.setLineStyle(SeriesLineStyle.SOLID); - new SwingWrapper(chart).displayChart(); + return chart; } } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/ExampleChart.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/ExampleChart.java new file mode 100644 index 0000000000000000000000000000000000000000..60c9cf863770df2a4d1d7c2a02be34433800b249 --- /dev/null +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/ExampleChart.java @@ -0,0 +1,33 @@ +/** + * Copyright (C) 2013 Xeiam LLC http://xeiam.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.xeiam.xchart.demo.charts; + +import com.xeiam.xchart.Chart; + +/** + * @author timmolter + */ +public interface ExampleChart { + + public Chart getChart(); + +}