diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart01.java index bac75519031598f38263c464565723f9942a38b3..bedf64209ee39f025f828613907ce5c753520512 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart01.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart01.java @@ -16,6 +16,8 @@ */ package org.knowm.xchart.demo.charts.bar; +import java.util.Arrays; + import org.knowm.xchart.Chart; import org.knowm.xchart.ChartBuilder; import org.knowm.xchart.StyleManager.ChartType; @@ -47,7 +49,7 @@ public class BarChart01 implements ExampleChart { // Create Chart Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Score Histogram").xAxisTitle("Score").yAxisTitle("Number").build(); - chart.addSeries("test 1", new double[] { 0, 1, 2, 3, 4 }, new double[] { 4, 5, 9, 6, 5 }); + chart.addCategorySeries("test 1", Arrays.asList(new Integer[] { 0, 1, 2, 3, 4 }), Arrays.asList(new Integer[] { 4, 5, 9, 6, 5 })); // Customize Chart chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart02.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart02.java index a20557c4e7588a78bc0269b6559345b846e4b69a..01b9c1f39012e8db40a8743bc28b3b600c73cd8a 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart02.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart02.java @@ -75,7 +75,7 @@ public class BarChart02 implements ExampleChart { xData.add(date); yData.add(-1 * 0.00000001 * ((random.nextInt(i) + 1))); } - Series series = chart.addSeries("Model 77", xData, yData); + Series series = chart.addCategorySeries("Model 77", xData, yData); series.setLineColor(SeriesColor.RED); chart.getStyleManager().setPlotGridLinesVisible(false); chart.getStyleManager().setBarFilled(false); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart03.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart03.java index 361b96377bc4f32ef27cb0255ea732e368437d6a..fb57944c46007bdd55b0376423ee4a4990a11cb0 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart03.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart03.java @@ -16,6 +16,8 @@ */ package org.knowm.xchart.demo.charts.bar; +import java.util.Arrays; + import org.knowm.xchart.Chart; import org.knowm.xchart.ChartBuilder; import org.knowm.xchart.StyleManager.ChartType; @@ -45,7 +47,7 @@ public class BarChart03 implements ExampleChart { // Create Chart Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Score vs. Age").xAxisTitle("Age").yAxisTitle("Score").build(); - chart.addSeries("males", new double[] { 10, 20, 30, 40 }, new double[] { 40, -30, -20, -60 }); + chart.addCategorySeries("males", Arrays.asList(new Integer[] { 10, 20, 30, 40 }), Arrays.asList(new Integer[] { 40, -30, -20, -60 })); return chart; } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart04.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart04.java index 2089a7764c6b528f18868aa8e86c59c6769e61cb..467258063e60992e2862bf88c13b4f7a2981c941 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart04.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart04.java @@ -16,6 +16,8 @@ */ package org.knowm.xchart.demo.charts.bar; +import java.util.Arrays; + import org.knowm.xchart.Chart; import org.knowm.xchart.ChartBuilder; import org.knowm.xchart.StyleManager.ChartType; @@ -47,8 +49,8 @@ public class BarChart04 implements ExampleChart { // Create Chart Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("XFactor vs. Age").xAxisTitle("Age").yAxisTitle("XFactor").build(); - chart.addSeries("female", new double[] { 10, 20, 30, 40, 50 }, new double[] { 50, 10, 20, 40, 35 }); - chart.addSeries("male", new double[] { 10, 20, 30, 40, 50 }, new double[] { 40, 30, 20, 0, 60 }); + chart.addCategorySeries("female", Arrays.asList(new Integer[] { 10, 20, 30, 40, 50 }), Arrays.asList(new Integer[] { 50, 10, 20, 40, 35 })); + chart.addCategorySeries("male", Arrays.asList(new Integer[] { 10, 20, 30, 40, 50 }), Arrays.asList(new Integer[] { 40, 30, 20, 0, 60 })); chart.getStyleManager().setYAxisMin(5); chart.getStyleManager().setYAxisMax(70); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart05.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart05.java index f6a2150a35acc6dc5274f89df2a24c4c470ed713..04d3bafee8f9279d22581d872f2b7f461c3f11c8 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart05.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart05.java @@ -49,10 +49,10 @@ public class BarChart05 implements ExampleChart { // Create Chart Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Temperature vs. Color").xAxisTitle("Color").yAxisTitle("Temperature").theme(ChartTheme.GGPlot2).build(); - chart.addSeries("fish", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Yellow" })), new ArrayList<Number>(Arrays.asList(new Number[] { -40, 30, 20, 60, - 60 }))); - chart.addSeries("worms", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Yellow" })), new ArrayList<Number>(Arrays.asList(new Number[] { 50, 10, -20, 40, - 60 }))); + chart.addCategorySeries("fish", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Yellow" })), new ArrayList<Number>(Arrays.asList(new Number[] { -40, 30, 20, + 60, 60 }))); + chart.addCategorySeries("worms", new ArrayList<String>(Arrays.asList(new String[] { "Blue", "Red", "Green", "Yellow", "Yellow" })), new ArrayList<Number>(Arrays.asList(new Number[] { 50, 10, -20, + 40, 60 }))); return chart; } diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart06.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart06.java index b7650a48979cf6743461910ba0033071e3b6fd36..64c088feae9d808d14700bd4f654ffd48f21b7ed 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart06.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart06.java @@ -53,8 +53,8 @@ public class BarChart06 implements ExampleChart { Histogram histogram1 = new Histogram(getGaussianData(10000), 30, -30, 30); Histogram histogram2 = new Histogram(getGaussianData(5000), 30, -30, 30); - chart.addSeries("histogram 1", histogram1.getxAxisData(), histogram1.getyAxisData()); - chart.addSeries("histogram 2", histogram2.getxAxisData(), histogram2.getyAxisData()); + chart.addCategorySeries("histogram 1", histogram1.getxAxisData(), histogram1.getyAxisData()); + chart.addCategorySeries("histogram 2", histogram2.getxAxisData(), histogram2.getyAxisData()); // Customize Chart chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart07.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart07.java index 1980e7ca270d8dc5ecd008174b812be268534336..5711df06ea911780d589e059a0a27bed7cc404ce 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart07.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart07.java @@ -53,9 +53,9 @@ public class BarChart07 implements ExampleChart { Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Score Histogram").xAxisTitle("Mean").yAxisTitle("Count").build(); Histogram histogram1 = new Histogram(getGaussianData(1000), 10, -30, 30); - chart.addSeries("histogram 1", histogram1.getxAxisData(), histogram1.getyAxisData()); + chart.addCategorySeries("histogram 1", histogram1.getxAxisData(), histogram1.getyAxisData()); Histogram histogram2 = new Histogram(getGaussianData(1000), 10, -30, 30); - chart.addSeries("histogram 2", histogram2.getxAxisData(), histogram2.getyAxisData()); + chart.addCategorySeries("histogram 2", histogram2.getxAxisData(), histogram2.getyAxisData()); // Customize Chart chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart08.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart08.java index 28d2d05bd21ddeeb796dda8e5570863d801c90bb..17725bba4b03bf3f5a1734b31b1ad9976920e1ff 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart08.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart08.java @@ -52,7 +52,7 @@ public class BarChart08 implements ExampleChart { Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Histogram").xAxisTitle("Mean").yAxisTitle("Count").build(); Histogram histogram1 = new Histogram(getGaussianData(10000), 10, -10, 10); - chart.addSeries("histogram", histogram1.getxAxisData(), histogram1.getyAxisData(), getFakeErrorData(histogram1.getxAxisData().size())); + chart.addCategorySeries("histogram", histogram1.getxAxisData(), histogram1.getyAxisData(), getFakeErrorData(histogram1.getxAxisData().size())); // Customize Chart chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart09.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart09.java index 164303e2e56e3a9c075c08ca17110dabd26541d6..f6f82b22f34f0abb43e69560d37e8a2ae0c7700b 100644 --- a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart09.java +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/bar/BarChart09.java @@ -51,9 +51,9 @@ public class BarChart09 implements ExampleChart { // Create Chart Chart chart = new ChartBuilder().chartType(ChartType.Bar).width(800).height(600).title("Value vs. Letter").xAxisTitle("Letter").yAxisTitle("Value").theme(ChartTheme.GGPlot2).build(); - chart.addSeries("China", new ArrayList<String>(Arrays.asList(new String[] { "A", "B", "C", "D", "E" })), new ArrayList<Number>(Arrays.asList(new Number[] { 11, 23, 20, 36, 5 }))); - Series series2 = chart.addSeries("World Ave.", new ArrayList<String>(Arrays.asList(new String[] { "A", "B", "C", "D", "E" })), new ArrayList<Number>(Arrays.asList(new Number[] { 13, 25, 22, 38, - 7 }))); + chart.addCategorySeries("China", new ArrayList<String>(Arrays.asList(new String[] { "A", "B", "C", "D", "E" })), new ArrayList<Number>(Arrays.asList(new Number[] { 11, 23, 20, 36, 5 }))); + Series series2 = chart.addCategorySeries("World Ave.", new ArrayList<String>(Arrays.asList(new String[] { "A", "B", "C", "D", "E" })), new ArrayList<Number>(Arrays.asList(new Number[] { 13, 25, + 22, 38, 7 }))); series2.setSeriesType(SeriesType.Line); // Customize Chart diff --git a/xchart/src/main/java/org/knowm/xchart/Chart.java b/xchart/src/main/java/org/knowm/xchart/Chart.java index 0b5f054bff1275ccef211704407fb8bc729a80cf..fa8bfef7f8227c551e427ae5e27bb33dd92145f8 100644 --- a/xchart/src/main/java/org/knowm/xchart/Chart.java +++ b/xchart/src/main/java/org/knowm/xchart/Chart.java @@ -106,7 +106,7 @@ public class Chart { } /** - * Add a Number series to the chart using Collections with error bars + * Add a series for a X-Y type chart using Lists with error bars * * @param seriesName * @param xData the X-Axis data @@ -120,7 +120,7 @@ public class Chart { } /** - * Add a series to the chart using Collections + * Add a series for a X-Y type chart using Lists * * @param seriesName * @param xData the X-Axis data @@ -133,7 +133,34 @@ public class Chart { } /** - * Add a series to the chart using double arrays + * Add a series for a Category type chart using Lists with error bars + * + * @param seriesName + * @param xData the X-Axis data + * @param yData the Y-Axis data + * @param errorBars the error bar data + * @return A Series object that you can set properties on + */ + public Series addCategorySeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { + + return chartInternal.addCategorySeries(seriesName, xData, yData, errorBars); + } + + /** + * Add a series for a Category type chart using Lists + * + * @param seriesName + * @param xData the X-Axis data + * @param yData the Y-Axis data + * @return A Series object that you can set properties on + */ + public Series addCategorySeries(String seriesName, List<?> xData, List<? extends Number> yData) { + + return addCategorySeries(seriesName, xData, yData, null); + } + + /** + * Add a series for a X-Y type chart using using double arrays * * @param seriesName * @param xData the X-Axis data @@ -146,7 +173,7 @@ public class Chart { } /** - * Add a series to the chart using double arrays with error bars + * Add a series for a X-Y type chart using using double arrays with error bars * * @param seriesName * @param xData the X-Axis data @@ -179,7 +206,7 @@ public class Chart { } /** - * Add a series to the chart using int arrays + * Add a series for a X-Y type chart using using int arrays * * @param seriesName * @param xData the X-Axis data @@ -192,7 +219,7 @@ public class Chart { } /** - * Add a series to the chart using int arrays with error bars + * Add a series for a X-Y type chart using using int arrays with error bars * * @param seriesName * @param xData the X-Axis data diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java index 315535a79c59d9f34cb9ca86f7a4991d3f6d49ae..d541294537ee6a2f02d65777a6e466a329e3a724 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/Axis.java @@ -24,6 +24,7 @@ import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import org.knowm.xchart.StyleManager.LegendPosition; +import org.knowm.xchart.internal.chartpart.ChartInternal.ChartInternalType; /** * Axis @@ -342,24 +343,25 @@ public class Axis implements ChartPart { private AxisTickCalculator getAxisTickCalculator(double workingSpace) { - if (getDirection() == Direction.X && getAxisType() == AxisType.String) { + if (getDirection() == Direction.X && getChartInternal().getChartInternalType() == ChartInternalType.Category) { return new AxisTickCategoryChartCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal()); } - else if (getDirection() == Direction.X && getChartInternal().getStyleManager().isXAxisLogarithmic() && getAxisType() != AxisType.Date) { + else if (getChartInternal().getChartInternalType() == ChartInternalType.XY && getAxisType() == AxisType.Date) { - return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); + return new AxisTickDateCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); } - else if (getDirection() == Direction.Y && getChartInternal().getStyleManager().isYAxisLogarithmic() && getAxisType() != AxisType.Date) { + else if (getDirection() == Direction.X && getChartInternal().getChartInternalType() == ChartInternalType.XY && getChartInternal().getStyleManager().isXAxisLogarithmic() + && getAxisType() != AxisType.Date) { return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); } - else if (getAxisType() == AxisType.Date) { + else if (getDirection() == Direction.Y && getChartInternal().getStyleManager().isYAxisLogarithmic() && getAxisType() != AxisType.Date) { - return new AxisTickDateCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); + return new AxisTickLogarithmicCalculator(getDirection(), workingSpace, getMin(), getMax(), getChartInternal().getStyleManager()); } else { // number diff --git a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java index f84885658062a13ffe8bf9cd6749e7ac49a3b259..d3fb433143201aab671b57431ffc4e46e771d054 100644 --- a/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java +++ b/xchart/src/main/java/org/knowm/xchart/internal/chartpart/ChartInternal.java @@ -40,6 +40,13 @@ public class ChartInternal { private int width; private int height; + protected enum ChartInternalType { + + XY, Category + } + + private ChartInternalType chartInternalType = null; + private Map<String, Series> seriesMap = new LinkedHashMap<String, Series>(); private SeriesColorMarkerLineStyleCycler seriesColorMarkerLineStyleCycler = new SeriesColorMarkerLineStyleCycler(); @@ -79,23 +86,13 @@ public class ChartInternal { */ public Series addSeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { - // Sanity checks - if (seriesName == null) { - throw new IllegalArgumentException("Series Name cannot be null!!!"); - } - if (yData == null) { - throw new IllegalArgumentException("Y-Axis data cannot be null!!!"); - } - if (yData.size() == 0) { - throw new IllegalArgumentException("Y-Axis data cannot be empty!!!"); - } - if (xData != null && xData.size() == 0) { - throw new IllegalArgumentException("X-Axis data cannot be empty!!!"); - } - // Sanity check - if (errorBars != null && errorBars.size() != yData.size()) { - throw new IllegalArgumentException("errorbars and Y-Axis sizes are not the same!!!"); + if (chartInternalType != null && chartInternalType != ChartInternalType.XY) { + throw new IllegalArgumentException("Cannot mix x-y and category series types! Don't call addSeries() and addCategorySeries() for the same chart!"); } + chartInternalType = ChartInternalType.XY; + + // Sanity checks + sanityCheck(seriesName, xData, yData, errorBars); Series series = null; if (xData != null) { @@ -104,21 +101,13 @@ public class ChartInternal { if (xData.size() != yData.size()) { throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!"); } - // inspect the series to see what kind of data it contains (Number, Date or String) - Iterator<?> itr = xData.iterator(); - Object dataPoint = itr.next(); - if (dataPoint instanceof Number) { - axisPair.getXAxis().setAxisType(AxisType.Number); - } - else if (dataPoint instanceof Date) { - axisPair.getXAxis().setAxisType(AxisType.Date); - } - else if (dataPoint instanceof String) { - axisPair.getXAxis().setAxisType(AxisType.String); - } - else { - throw new IllegalArgumentException("Series data must be either Number, Date or String type!!!"); + + // inspect the series to see what kind of data it contains (Number, Date) + AxisType axisType = setXAxisType(xData); + if (!(axisType == AxisType.Number || axisType == AxisType.Date)) { + throw new IllegalArgumentException("X-Axis data must be of type Number or Date!!!"); } + axisPair.getYAxis().setAxisType(AxisType.Number); series = new Series(seriesName, xData, axisPair.getXAxis().getAxisType(), yData, axisPair.getYAxis().getAxisType(), errorBars, seriesColorMarkerLineStyleCycler .getNextSeriesColorMarkerLineStyle()); @@ -134,7 +123,117 @@ public class ChartInternal { .getNextSeriesColorMarkerLineStyle()); } - // set series type based on chart type, but only if it's not explicitly set on the series yet. + // set series type + setSeriesType(series); + + if (seriesMap.keySet().contains(seriesName)) { + throw new IllegalArgumentException("Series name >" + seriesName + "< has already been used. Use unique names for each series!!!"); + } + + seriesMap.put(seriesName, series); + + return series; + } + + /** + * @param seriesName + * @param xData + * @param yData + * @param errorBars + * @return Series + */ + public Series addCategorySeries(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { + + if (chartInternalType != null && chartInternalType != ChartInternalType.Category) { + throw new IllegalArgumentException("Cannot mix x-y and category series types! Don't call addSeries() and addCategorySeries() for the same chart!"); + } + chartInternalType = ChartInternalType.Category; + + // Sanity checks + sanityCheck(seriesName, xData, yData, errorBars); + if (xData == null) { + throw new IllegalArgumentException("Y-Axis data cannot be null!!!"); + } + if (xData.size() != yData.size()) { + throw new IllegalArgumentException("X and Y-Axis sizes are not the same!!!"); + } + + // inspect the series to see what kind of data it contains (Number, Date, String) + setXAxisType(xData); + + axisPair.getYAxis().setAxisType(AxisType.Number); + Series series = new Series(seriesName, xData, axisPair.getXAxis().getAxisType(), yData, axisPair.getYAxis().getAxisType(), errorBars, seriesColorMarkerLineStyleCycler + .getNextSeriesColorMarkerLineStyle()); + + // set series type + setSeriesType(series); + + if (seriesMap.keySet().contains(seriesName)) { + throw new IllegalArgumentException("Series name >" + seriesName + "< has already been used. Use unique names for each series!!!"); + } + + seriesMap.put(seriesName, series); + + return series; + } + + private void sanityCheck(String seriesName, List<?> xData, List<? extends Number> yData, List<? extends Number> errorBars) { + + if (seriesName == null) { + throw new IllegalArgumentException("Series Name cannot be null!!!"); + } + if (yData == null) { + throw new IllegalArgumentException("Y-Axis data cannot be null!!!"); + } + if (yData.size() == 0) { + throw new IllegalArgumentException("Y-Axis data cannot be empty!!!"); + } + if (xData != null && xData.size() == 0) { + throw new IllegalArgumentException("X-Axis data cannot be empty!!!"); + } + if (errorBars != null && errorBars.size() != yData.size()) { + throw new IllegalArgumentException("errorbars and Y-Axis sizes are not the same!!!"); + } + + } + + /** + * Sets the axis type based on the data contained in the xData argument + * + * @param xData + * @return + */ + private AxisType setXAxisType(List<?> xData) { + + AxisType axisType; + + Iterator<?> itr = xData.iterator(); + Object dataPoint = itr.next(); + if (dataPoint instanceof Number) { + axisType = AxisType.Number; + axisPair.getXAxis().setAxisType(axisType); + } + else if (dataPoint instanceof Date) { + axisType = AxisType.Date; + axisPair.getXAxis().setAxisType(axisType); + } + else if (dataPoint instanceof String) { + axisType = AxisType.String; + axisPair.getXAxis().setAxisType(axisType); + } + else { + throw new IllegalArgumentException("Series data must be either Number, Date or String type!!!"); + } + return axisType; + } + + /** + * set series type based on chart type, but only if it's not explicitly set on the series yet. + * + * @param series + */ + private void setSeriesType(Series series) { + switch (getStyleManager().getChartType()) { case Line: if (series.getSeriesType() == null) { @@ -152,6 +251,7 @@ public class ChartInternal { } break; case Bar: + // TODO Not Yet Supported if (series.getSeriesType() == null) { series.setSeriesType(Series.SeriesType.Bar); } @@ -162,14 +262,6 @@ public class ChartInternal { } break; } - - if (seriesMap.keySet().contains(seriesName)) { - throw new IllegalArgumentException("Series name >" + seriesName + "< has already been used. Use unique names for each series!!!"); - } - - seriesMap.put(seriesName, series); - - return series; } /** @@ -247,7 +339,7 @@ public class ChartInternal { * * @return */ - public Legend getChartLegend() { + protected Legend getChartLegend() { return chartLegend; } @@ -267,11 +359,16 @@ public class ChartInternal { * * @return */ - public Plot getPlot() { + protected Plot getPlot() { return plot; } + public ChartInternalType getChartInternalType() { + + return chartInternalType; + } + public int getWidth() { return width;