diff --git a/xchart-core/src/main/java/com/xeiam/xchart/Chart.java b/xchart-core/src/main/java/com/xeiam/xchart/Chart.java index a63b0d37f352eaa07517dc573c4950e78ebdf201..5ca946715fba435e9ebe878ed71f0f077fc239b6 100644 --- a/xchart-core/src/main/java/com/xeiam/xchart/Chart.java +++ b/xchart-core/src/main/java/com/xeiam/xchart/Chart.java @@ -97,12 +97,6 @@ public class Chart { plot.paint(g); g.dispose(); - - // reset static Ids - SeriesColor.resetId(); - SeriesLineStyle.resetId(); - SeriesMarker.resetId(); - } // PUBLIC SETTERS diff --git a/xchart-core/src/main/java/com/xeiam/xchart/Series.java b/xchart-core/src/main/java/com/xeiam/xchart/Series.java index 8997902cfec941e7e6eb650932cd94dc2ac4bd2a..c513961513f40cdcb66cfd34e19caf1ba66ead76 100644 --- a/xchart-core/src/main/java/com/xeiam/xchart/Series.java +++ b/xchart-core/src/main/java/com/xeiam/xchart/Series.java @@ -24,6 +24,7 @@ import java.util.Iterator; import com.xeiam.xchart.internal.chartpart.Axis.AxisType; import com.xeiam.xchart.internal.markers.Marker; +import com.xeiam.xchart.internal.misc.SeriesColorMarkerLineStyle; /** * A Series containing X and Y data to be plotted on a Chart @@ -74,13 +75,18 @@ public class Series { * @param yAxisType * @param errorBars */ - public Series(String name, Collection<?> xData, AxisType xAxisType, Collection<Number> yData, AxisType yAxisType, Collection<Number> errorBars) { + public Series(String name, Collection<?> xData, AxisType xAxisType, Collection<Number> yData, AxisType yAxisType, Collection<Number> errorBars, SeriesColorMarkerLineStyle seriesColorMarkerLineStyle) { this.name = name; this.xData = xData; this.yData = yData; this.errorBars = errorBars; + strokeColor = seriesColorMarkerLineStyle.getColor(); + markerColor = seriesColorMarkerLineStyle.getColor(); + marker = seriesColorMarkerLineStyle.getMarker(); + stroke = seriesColorMarkerLineStyle.getStroke(); + // xData BigDecimal[] xMinMax = findMinMax(xData, xAxisType); xMin = xMinMax[0]; @@ -98,13 +104,6 @@ public class Series { // System.out.println(yMin); // System.out.println(yMax); - Color color = SeriesColor.getNextAWTColor(); - strokeColor = color; - markerColor = color; - - marker = SeriesMarker.getNextMarker(); - stroke = SeriesLineStyle.getNextBasicStroke(); - } /** @@ -178,7 +177,7 @@ public class Series { public void setLineColor(SeriesColor lineColor) { - strokeColor = SeriesColor.getAWTColor(lineColor); + strokeColor = lineColor.getColor(); } public void setLineColor(java.awt.Color lineColor) { @@ -186,16 +185,26 @@ public class Series { strokeColor = lineColor; } + /** + * Sets the marker for the series + * + * @param marker + */ public void setMarker(SeriesMarker marker) { - this.marker = SeriesMarker.getMarker(marker); + this.marker = marker.getMarker(); } - public void setMarkerColor(SeriesColor lineColor) { + public void setMarkerColor(SeriesColor markerColor) { - this.markerColor = SeriesColor.getAWTColor(lineColor); + this.markerColor = markerColor.getColor(); } + /** + * Sets the marker color for the series + * + * @param lineColor + */ public void setMarkerColor(java.awt.Color lineColor) { this.markerColor = lineColor; diff --git a/xchart-core/src/main/java/com/xeiam/xchart/SeriesColor.java b/xchart-core/src/main/java/com/xeiam/xchart/SeriesColor.java index 993692ece059b272c58c59abb5e78db207d8aff2..c3a8fbf8978d29eb9f11ee29c0f67b80b2b04a39 100644 --- a/xchart-core/src/main/java/com/xeiam/xchart/SeriesColor.java +++ b/xchart-core/src/main/java/com/xeiam/xchart/SeriesColor.java @@ -16,9 +16,6 @@ package com.xeiam.xchart; import java.awt.Color; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; /** * Pre-defined Colors used for Series Lines and Markers @@ -61,58 +58,55 @@ public enum SeriesColor { BROWN(10, new Color(150, 74, 0)), /** BLACK */ - BLACK(11, new Color(0, 0, 0)), + BLACK(11, new Color(0, 0, 0)); - /** RANDOM */ - RANDOM(12, new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255))); + /** The index */ + private int index; - int id; - Color color; + /** The AWT Color */ + private Color color; - private static int nextId = 0; - - private static final Map<Integer, SeriesColor> idLookup = new HashMap<Integer, SeriesColor>(); - static { - for (SeriesColor seriesColor : EnumSet.allOf(SeriesColor.class)) { - idLookup.put(seriesColor.getId(), seriesColor); - } - } - - private Integer getId() { - - return id; - } - - protected static void resetId() { + /** + * Constructor + * + * @param index + * @param color + */ + private SeriesColor(int index, Color color) { - nextId = 0; + this.index = index; + this.color = color; } - protected static Color getAWTColor(SeriesColor seriesColor) { + /** + * Gets the SeriesColor's index + * + * @return + */ + public Integer getIndex() { - return seriesColor.color; + return index; } - protected static Color getNextAWTColor() { + /** + * Gets the SeriesColor's AWT Color + * + * @return the AWT Color + */ + public Color getColor() { - SeriesColor seriesColor = idLookup.get(nextId); - if (seriesColor == null) { - // rotate thru from beginning - resetId(); - } - return idLookup.get(nextId++).color; + return color; } /** - * Constructor + * get the AWT Color given a SeriesColor * - * @param id - * @param color + * @param seriesColor + * @return the AWT Color */ - private SeriesColor(int id, Color color) { + public Color getAWTColor(SeriesColor seriesColor) { - this.id = id; - this.color = color; + return seriesColor.color; } } diff --git a/xchart-core/src/main/java/com/xeiam/xchart/SeriesLineStyle.java b/xchart-core/src/main/java/com/xeiam/xchart/SeriesLineStyle.java index cc17433d20f5e32193711600010ea801a096228b..1801ac0101ef911fea68b75d92149528b482ae35 100644 --- a/xchart-core/src/main/java/com/xeiam/xchart/SeriesLineStyle.java +++ b/xchart-core/src/main/java/com/xeiam/xchart/SeriesLineStyle.java @@ -16,9 +16,6 @@ package com.xeiam.xchart; import java.awt.BasicStroke; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; /** * Pre-defined Line Styles used for Series Lines @@ -42,39 +39,42 @@ public enum SeriesLineStyle { /** DOT_DOT */ DOT_DOT(3, new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, new float[] { 1.0f, 1.0f }, 0.0f)); - int id; + /** The index */ + private int index; - BasicStroke basicStroke; - - private static int nextId = 0; + /** The basicStroke */ + private BasicStroke basicStroke; /** * Constructor * - * @param id - * @param color + * @param index + * @param basicStroke */ - private SeriesLineStyle(int id, BasicStroke basicStroke) { + private SeriesLineStyle(int index, BasicStroke basicStroke) { - this.id = id; + this.index = index; this.basicStroke = basicStroke; } - private static final Map<Integer, SeriesLineStyle> idLookup = new HashMap<Integer, SeriesLineStyle>(); - static { - for (SeriesLineStyle seriesLineStyle : EnumSet.allOf(SeriesLineStyle.class)) { - idLookup.put(seriesLineStyle.getId(), seriesLineStyle); - } - } - - private Integer getId() { + /** + * Gets the SeriesLineStyle's index + * + * @return + */ + public Integer getIndex() { - return id; + return index; } - protected static void resetId() { + /** + * Gets the SeriesLineStyle's BasicStroke + * + * @return the BasicStroke + */ + public BasicStroke getBasicStroke() { - nextId = 0; + return basicStroke; } /** @@ -88,19 +88,4 @@ public enum SeriesLineStyle { return seriesMarker.basicStroke; } - /** - * Gets the next BasicStroke - * - * @return the next BasicStroke - */ - protected static BasicStroke getNextBasicStroke() { - - SeriesLineStyle seriesLineStyle = idLookup.get(nextId); - if (seriesLineStyle == null) { - // rotate thru from beginning - resetId(); - } - return idLookup.get(nextId++).basicStroke; - } - } diff --git a/xchart-core/src/main/java/com/xeiam/xchart/SeriesMarker.java b/xchart-core/src/main/java/com/xeiam/xchart/SeriesMarker.java index a380236822ec29b5c7c75556319dc9fb2a501c3f..04db9f0072b32b7683efad73004884b9e3dbcc53 100644 --- a/xchart-core/src/main/java/com/xeiam/xchart/SeriesMarker.java +++ b/xchart-core/src/main/java/com/xeiam/xchart/SeriesMarker.java @@ -15,10 +15,6 @@ */ package com.xeiam.xchart; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - import com.xeiam.xchart.internal.markers.Circle; import com.xeiam.xchart.internal.markers.Diamond; import com.xeiam.xchart.internal.markers.Marker; @@ -51,52 +47,42 @@ public enum SeriesMarker { /** TRIANGLE_UP */ TRIANGLE_UP(4, new TriangleUp()); - int id; - Marker marker; - private static int nextId = 0; - - private static final Map<Integer, SeriesMarker> idLookup = new HashMap<Integer, SeriesMarker>(); - static { - for (SeriesMarker seriesMarker : EnumSet.allOf(SeriesMarker.class)) { - idLookup.put(seriesMarker.getId(), seriesMarker); - } - } + /** The index */ + private int index; - private Integer getId() { - - return id; - } + /** The Marker */ + private Marker marker; - protected static void resetId() { - - nextId = 0; - } - - protected static Marker getMarker(SeriesMarker seriesMarker) { + /** + * Constructor + * + * @param index + * @param marker + */ + private SeriesMarker(int index, Marker marker) { - return seriesMarker.marker; + this.index = index; + this.marker = marker; } - protected static Marker getNextMarker() { + /** + * Gets the SeriesMarker index + * + * @return + */ + public Integer getIndex() { - SeriesMarker seriesMarker = idLookup.get(nextId); - if (seriesMarker == null) { - // rotate thru from beginning - resetId(); - } - return idLookup.get(nextId++).marker; + return index; } /** - * Constructor + * Gets the SeriesMarker marker * - * @param id - * @param color + * @return */ - private SeriesMarker(int id, Marker marker) { + public Marker getMarker() { - this.id = id; - this.marker = marker; + return marker; } } diff --git a/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java b/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java index e51aec8c4ddd0e178e085d4cdceb462aa88eff56..4bab5717d8240e5ad8e615c3cec56756c9012246 100644 --- a/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java +++ b/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/AxisPair.java @@ -28,6 +28,7 @@ import com.xeiam.xchart.Chart; import com.xeiam.xchart.Series; import com.xeiam.xchart.internal.chartpart.Axis.AxisType; import com.xeiam.xchart.internal.interfaces.IChartPart; +import com.xeiam.xchart.internal.misc.SeriesColorMarkerLineStyleCycler; /** * @author timmolter @@ -44,10 +45,12 @@ public class AxisPair implements IChartPart { public Axis xAxis; public Axis yAxis; + public SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(); + /** - * Constructor. + * Constructor * - * @param chart the chart + * @param the parent chart */ public AxisPair(Chart chart) { @@ -91,15 +94,15 @@ public class AxisPair implements IChartPart { xAxis.setAxisType(AxisType.DATE); } yAxis.setAxisType(AxisType.NUMBER); - series = new Series(seriesName, xData, xAxis.axisType, yData, yAxis.axisType, errorBars); + series = new Series(seriesName, xData, xAxis.axisType, yData, yAxis.axisType, errorBars, seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle()); } else { // generate xData Collection<Number> generatedXData = new ArrayList<Number>(); - for (int i = 1; i < yData.size(); i++) { + for (int i = 1; i < yData.size() + 1; i++) { generatedXData.add(i); } xAxis.setAxisType(AxisType.NUMBER); yAxis.setAxisType(AxisType.NUMBER); - series = new Series(seriesName, generatedXData, xAxis.axisType, yData, yAxis.axisType, errorBars); + series = new Series(seriesName, generatedXData, xAxis.axisType, yData, yAxis.axisType, errorBars, seriesColorMarkerLineStyleCycler.getNextSeriesColorMarkerLineStyle()); } // Sanity check @@ -129,12 +132,25 @@ public class AxisPair implements IChartPart { return chart.chartLegend.getBounds(); } + /** + * Gets the percentage of working space allowed for tick marks + * + * @param workingSpace + * @return + */ protected static int getTickSpace(int workingSpace) { return (int) (workingSpace * 0.95); } - protected static int getMargin(int workingSpace, int tickSpace) { + /** + * Gets the offset for the beginning of the tick marks + * + * @param workingSpace + * @param tickSpace + * @return + */ + protected static int getTickStartOffset(int workingSpace, int tickSpace) { int marginSpace = workingSpace - tickSpace; return (int) (marginSpace / 2.0); diff --git a/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java b/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java index 4004eb8f2d5fdd05d664c2c7d339428cc3ee3432..f8e7dfb2b3bc17b354b9c289f7fecce3c9817063 100644 --- a/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java +++ b/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java @@ -154,7 +154,7 @@ public class AxisTick implements IChartPart, IHideable { int tickSpace = AxisPair.getTickSpace(workingSpace); // System.out.println("tickSpace= " + tickSpace); - int margin = AxisPair.getMargin(workingSpace, tickSpace); + int margin = AxisPair.getTickStartOffset(workingSpace, tickSpace); // a check if all axis data are the exact same values if (axis.max == axis.min) { diff --git a/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java b/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java index 96ea20cc22227f62212b62b74c39bd760eaa8864..7dd8fa7c8637b28ad57ee06c597da134b200432d 100644 --- a/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java +++ b/xchart-core/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContent.java @@ -64,11 +64,11 @@ public class PlotContent implements IChartPart { // X-Axis int xTickSpace = AxisPair.getTickSpace((int) bounds.getWidth()); - int xLeftMargin = AxisPair.getMargin((int) bounds.getWidth(), xTickSpace); + int xLeftMargin = AxisPair.getTickStartOffset((int) bounds.getWidth(), xTickSpace); // Y-Axis int yTickSpace = AxisPair.getTickSpace((int) bounds.getHeight()); - int yTopMargin = AxisPair.getMargin((int) bounds.getHeight(), yTickSpace); + int yTopMargin = AxisPair.getTickStartOffset((int) bounds.getHeight(), yTickSpace); // data points Collection<?> xData = series.xData; diff --git a/xchart-core/src/main/java/com/xeiam/xchart/internal/misc/SeriesColorMarkerLineStyle.java b/xchart-core/src/main/java/com/xeiam/xchart/internal/misc/SeriesColorMarkerLineStyle.java new file mode 100644 index 0000000000000000000000000000000000000000..d9e19b70388ebbcded795b9ea292fe71a68dd278 --- /dev/null +++ b/xchart-core/src/main/java/com/xeiam/xchart/internal/misc/SeriesColorMarkerLineStyle.java @@ -0,0 +1,69 @@ +/** + * 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.internal.misc; + +import java.awt.BasicStroke; +import java.awt.Color; + +import com.xeiam.xchart.internal.markers.Marker; + +/** + * A DTO to hold the Series' Color, Marker, and LineStyle + * + * @author timmolter + */ +public final class SeriesColorMarkerLineStyle { + + private final Color color; + private final Marker marker; + private final BasicStroke stroke; + + /** + * Constructor + * + * @param color + * @param marker + * @param stroke + */ + public SeriesColorMarkerLineStyle(Color color, Marker marker, BasicStroke stroke) { + + this.color = color; + this.marker = marker; + this.stroke = stroke; + } + + public Color getColor() { + + return color; + } + + public Marker getMarker() { + + return marker; + } + + public BasicStroke getStroke() { + + return stroke; + } + +} diff --git a/xchart-core/src/main/java/com/xeiam/xchart/internal/misc/SeriesColorMarkerLineStyleCycler.java b/xchart-core/src/main/java/com/xeiam/xchart/internal/misc/SeriesColorMarkerLineStyleCycler.java new file mode 100644 index 0000000000000000000000000000000000000000..1fbed461311a39e21d6d844a3788cbd91ec7590c --- /dev/null +++ b/xchart-core/src/main/java/com/xeiam/xchart/internal/misc/SeriesColorMarkerLineStyleCycler.java @@ -0,0 +1,104 @@ +/** + * 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.internal.misc; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +import com.xeiam.xchart.SeriesColor; +import com.xeiam.xchart.SeriesLineStyle; +import com.xeiam.xchart.SeriesMarker; + +/** + * Cycles through the different colors, markers, and strokes in a predetermined way + * + * @author timmolter + */ +public class SeriesColorMarkerLineStyleCycler { + + /** a map holding the SeriesColors */ + private final Map<Integer, SeriesColor> seriesColorMap = new HashMap<Integer, SeriesColor>(); + + /** a map holding the SeriesMarkers */ + private final Map<Integer, SeriesMarker> seriesMarkerMap = new HashMap<Integer, SeriesMarker>(); + + /** a map holding the SeriesLineStyles */ + private final Map<Integer, SeriesLineStyle> seriesLineStyleMap = new HashMap<Integer, SeriesLineStyle>(); + + /** an internal counter */ + private int colorCounter = 0; + private int markerCounter = 0; + private int strokeCounter = 0; + + /** + * Constructor + */ + public SeriesColorMarkerLineStyleCycler() { + + // 1. Color + for (SeriesColor seriesColor : EnumSet.allOf(SeriesColor.class)) { + seriesColorMap.put(seriesColor.getIndex(), seriesColor); + } + + // 2. Marker + for (SeriesMarker seriesMarker : EnumSet.allOf(SeriesMarker.class)) { + if (seriesMarker.getIndex() >= 0) { // skip Marker.NONE + seriesMarkerMap.put(seriesMarker.getIndex(), seriesMarker); + } + } + + // 3. Stroke + for (SeriesLineStyle seriesLineStyle : EnumSet.allOf(SeriesLineStyle.class)) { + seriesLineStyleMap.put(seriesLineStyle.getIndex(), seriesLineStyle); + } + } + + /** + * Get the next SeriesColorMarkerLineStyle + * + * @return the next SeriesColorMarkerLineStyle + */ + public SeriesColorMarkerLineStyle getNextSeriesColorMarkerLineStyle() { + + // 1. Color - cycle through colors one by one + if (colorCounter >= seriesColorMap.size()) { + colorCounter = 0; + strokeCounter++; + } + SeriesColor seriesColor = seriesColorMap.get(colorCounter++); + + // 2. Stroke - cycle through strokes one by one but only after a color cycle + if (strokeCounter >= seriesLineStyleMap.size()) { + strokeCounter = 0; + } + SeriesLineStyle seriesLineStyle = seriesLineStyleMap.get(strokeCounter); + + // 3. Marker - cycle through markers one by one + if (markerCounter >= seriesMarkerMap.size()) { + markerCounter = 0; + } + SeriesMarker marker = seriesMarkerMap.get(markerCounter++); + + return new SeriesColorMarkerLineStyle(seriesColor.getColor(), marker.getMarker(), seriesLineStyle.getBasicStroke()); + } +} diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/demo/ChartDemo.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/XChartDemo.java similarity index 97% rename from xchart-examples/src/main/java/com/xeiam/xchart/demo/ChartDemo.java rename to xchart-examples/src/main/java/com/xeiam/xchart/demo/XChartDemo.java index ad23a16c2385fe4680d042d5e203857f85a35788..ac62cdea7e7a823c23d50961556740e4a2a5ac7e 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/demo/ChartDemo.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/XChartDemo.java @@ -43,7 +43,7 @@ import com.xeiam.xchart.demo.charts.Example9; * * @author timmolter */ -public class ChartDemo extends JPanel implements TreeSelectionListener { +public class XChartDemo extends JPanel implements TreeSelectionListener { /** The main split frame */ private JSplitPane splitPane; @@ -57,7 +57,7 @@ public class ChartDemo extends JPanel implements TreeSelectionListener { /** * Constructor */ - public ChartDemo() { + public XChartDemo() { super(new GridLayout(1, 0)); @@ -166,7 +166,7 @@ public class ChartDemo extends JPanel implements TreeSelectionListener { frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Add content to the window. - frame.add(new ChartDemo()); + frame.add(new XChartDemo()); // Display the window. frame.pack(); diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example2.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example2.java index f896ba6aad128ad32b4144eb0ef2fa12b9e60e79..038546641eeeeeb2268c7f20dcc3ce9721e613b4 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example2.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example2.java @@ -34,7 +34,7 @@ public class Example2 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new Example10(); + ExampleChart exampleChart = new Example2(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example3.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example3.java index 1d928eb6a2a43756259ee6281a322b6a496df0fa..d35cab80d1117f983c343b38992437102a91b06f 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example3.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example3.java @@ -30,7 +30,7 @@ public class Example3 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new Example10(); + ExampleChart exampleChart = new Example3(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example5.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example5.java index 70bb164ff96847fe49349638332865b11b4dd4b5..4e1a130b3b05948dc2bf535725102591cbf936eb 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example5.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example5.java @@ -27,7 +27,7 @@ public class Example5 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new Example10(); + ExampleChart exampleChart = new Example5(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example6.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example6.java index b12bd339978120ead037891690c08207f51ee77a..91c9a5af92c903f10e605a4fc8d3860109f43516 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example6.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example6.java @@ -27,7 +27,7 @@ public class Example6 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new Example10(); + ExampleChart exampleChart = new Example6(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example7.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example7.java index 64d7d622d45d2733ba16318e8ad262e9115ee1b5..28b01708a45ec1f33a55341cc6f4f586ca076a2c 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example7.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example7.java @@ -30,7 +30,7 @@ public class Example7 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new Example10(); + ExampleChart exampleChart = new Example7(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example8.java b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example8.java index 89fe79521aeca8f595f8686f5c10c8b916adc7c7..c6c23fddcd3b37d0e744957b35e373d678aea584 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example8.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/demo/charts/Example8.java @@ -34,7 +34,7 @@ public class Example8 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new Example10(); + ExampleChart exampleChart = new Example8(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } diff --git a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example1.java b/xchart-examples/src/main/java/com/xeiam/xchart/example/Example1.java index bf0ade2373673bcedf295463c0b325fc63dc6189..b5d3a51a301b08309330db7a060940be361218cc 100644 --- a/xchart-examples/src/main/java/com/xeiam/xchart/example/Example1.java +++ b/xchart-examples/src/main/java/com/xeiam/xchart/example/Example1.java @@ -18,8 +18,8 @@ package com.xeiam.xchart.example; import java.util.Arrays; import java.util.Collection; -import com.xeiam.xchart.BitmapEncoder; import com.xeiam.xchart.Chart; +import com.xeiam.xchart.SwingWrapper; /** * Creates a simple Chart and saves it as a PNG and JPEG image file. @@ -30,18 +30,31 @@ public class Example1 { public static void main(String[] args) throws Exception { - Collection<Number> xData = Arrays.asList(new Number[] { 0.0, 1.0, 2.0 }); - Collection<Number> yData = Arrays.asList(new Number[] { 0.0, 1.0, 2.0 }); + double[] yData = new double[] { 2.0, 1.0, 0.0 }; + + Collection<Number> yData2 = Arrays.asList(new Number[] { 0.0, 1.0, 2.0 }); + + Collection<Number> yData3 = Arrays.asList(new Number[] { 0.0, 0.0, 2.0 }); + + Collection<Number> yData4 = Arrays.asList(new Number[] { 0.0, 3.0, 2.0 }); + + Collection<Number> yData5 = Arrays.asList(new Number[] { 3.0, 3.0, 2.0 }); // Create Chart Chart chart = new Chart(500, 400); chart.setTitle("Sample Chart"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); - chart.addSeries("y(x)", xData, yData); + chart.addSeries("y(x)", null, yData); + chart.addSeries("w(t)", null, yData2); + chart.addSeries("f(k)", null, yData3); + chart.addSeries("f(h)", null, yData4); + chart.addSeries("g(h)", null, yData5); + + new SwingWrapper(chart).displayChart(); - BitmapEncoder.savePNG(chart, "./Sample_Chart.png"); - BitmapEncoder.saveJPG(chart, "./Sample_Chart.jpg", 0.95f); + // BitmapEncoder.savePNG(chart, "./Sample_Chart.png"); + // BitmapEncoder.saveJPG(chart, "./Sample_Chart.jpg", 0.95f); } }