diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java index 8690b96fcf4058cf0b2342d354178c74ac2dbd1e..2a1e0c2215f4b69d250f23b945aec8a3b0f43477 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/XChartDemo.java @@ -44,8 +44,8 @@ import com.xeiam.xchart.demo.charts.date.DateChart06; import com.xeiam.xchart.demo.charts.date.DateChart07; import com.xeiam.xchart.demo.charts.line.LineChart01; import com.xeiam.xchart.demo.charts.line.LineChart02; -import com.xeiam.xchart.demo.charts.line.LineChart09; -import com.xeiam.xchart.demo.charts.line.LineChart10; +import com.xeiam.xchart.demo.charts.line.LineChart03; +import com.xeiam.xchart.demo.charts.line.LineChart04; import com.xeiam.xchart.demo.charts.scatter.ScatterChart01; import com.xeiam.xchart.demo.charts.scatter.ScatterChart02; import com.xeiam.xchart.demo.charts.scatter.ScatterChart03; @@ -147,10 +147,10 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { chart = new DefaultMutableTreeNode(new ChartInfo("LineChart02 - Customized Series Style", new LineChart02().getChart())); category.add(chart); - chart = new DefaultMutableTreeNode(new ChartInfo("LineChart09 - Extensive chart customization", new LineChart09().getChart())); + chart = new DefaultMutableTreeNode(new ChartInfo("LineChart03 - Extensive Chart Customization", new LineChart03().getChart())); category.add(chart); - chart = new DefaultMutableTreeNode(new ChartInfo("LineChart10 - Plots Hundreds of Series on One Plot", new LineChart10().getChart())); + chart = new DefaultMutableTreeNode(new ChartInfo("LineChart04 - Plots Hundreds of Series on One Plot", new LineChart04().getChart())); category.add(chart); // Scatter category diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java index 1acc6a6b6833258e9a0ef766e6254afeae2ed545..29cccef44f5f0af12a5930bf3f8818972d22806c 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart01.java @@ -60,7 +60,7 @@ public class LineChart01 implements ExampleChart { // Customize Chart chart.getStyleManager().setChartTitleVisible(false); chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); - chart.getStyleManager().setYAxisLogarithmic(true); + chart.getStyleManager().setyAxisLogarithmic(true); // Series Series series = chart.addSeries("10^x", xData1, yData1); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart09.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java similarity index 82% rename from xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart09.java rename to xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java index 701ee74e84118f9168c22b1df826665b4c9f3ea7..a514c0fe4dd2969fb1f57f6544e4340273064519 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart09.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java @@ -33,15 +33,16 @@ import com.xeiam.xchart.style.ChartColor; import com.xeiam.xchart.style.SeriesColor; import com.xeiam.xchart.style.SeriesLineStyle; import com.xeiam.xchart.style.SeriesMarker; +import com.xeiam.xchart.style.StyleManager.LegendPosition; /** - * Extensive chart customization + * Extensive Chart Customization */ -public class LineChart09 implements ExampleChart { +public class LineChart03 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new LineChart09(); + ExampleChart exampleChart = new LineChart03(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } @@ -70,7 +71,7 @@ public class LineChart09 implements ExampleChart { } // Customize Chart - chart.setChartTitle("LineChart09"); + chart.setChartTitle("LineChart03"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.getStyleManager().setPlotBackgroundColor(ChartColor.getAWTColor(ChartColor.GREY)); @@ -78,12 +79,18 @@ public class LineChart09 implements ExampleChart { chart.getStyleManager().setChartBackgroundColor(Color.WHITE); chart.getStyleManager().setLegendBackgroundColor(Color.PINK); chart.getStyleManager().setChartFontColor(Color.MAGENTA); + chart.getStyleManager().setChartTitleBackgroundColor(new Color(0, 222, 0)); + chart.getStyleManager().setPlotGridLinesVisible(false); + chart.getStyleManager().setAxisTickPadding(20); + chart.getStyleManager().setAxisTickMarkLength(15); + chart.getStyleManager().setPlotPadding(20); chart.getStyleManager().setChartTitleFont(new Font(Font.MONOSPACED, Font.BOLD, 24)); chart.getStyleManager().setLegendFont(new Font(Font.SERIF, Font.PLAIN, 18)); + chart.getStyleManager().setLegendPosition(LegendPosition.InsideSE); chart.getStyleManager().setAxisTitleFont(new Font(Font.SANS_SERIF, Font.ITALIC, 18)); chart.getStyleManager().setAxisTickLabelsFont(new Font(Font.SERIF, Font.PLAIN, 11)); chart.getStyleManager().setDatePattern("dd-MMM"); - chart.getStyleManager().setNormalDecimalPattern("#.000"); + chart.getStyleManager().setNormalDecimalPattern("#0.000"); chart.getStyleManager().setLocale(Locale.GERMAN); Series series = chart.addDateSeries("Fake Data", xData, yData); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart10.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart04.java similarity index 92% rename from xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart10.java rename to xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart04.java index 479af8b06b6f3e24f562c98e0ed944f247a52f81..3e9d8f452c899d12537cef08de46170658bd4f96 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart10.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart04.java @@ -26,11 +26,11 @@ import com.xeiam.xchart.style.SeriesMarker; /** * Plots Hundreds of Series on One Plot */ -public class LineChart10 implements ExampleChart { +public class LineChart04 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new LineChart10(); + ExampleChart exampleChart = new LineChart04(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } @@ -42,7 +42,7 @@ public class LineChart10 implements ExampleChart { Chart chart = new Chart(800, 600); // Customize Chart - chart.setChartTitle("LineChart10"); + chart.setChartTitle("LineChart04"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); chart.getStyleManager().setLegendVisible(false); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart02.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart02.java index 1dd235069b7f90f9d7d7e588f40f89a8fe5a0885..42951986c34af1a040a5c0c27517a7c5a9c5e859 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart02.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart02.java @@ -62,7 +62,7 @@ public class ScatterChart02 implements ExampleChart { Chart chart = new Chart(800, 600); chart.setChartTitle("Logarithmic Data"); chart.getStyleManager().setChartType(ChartType.Scatter); - chart.getStyleManager().setXAxisLogarithmic(true); + chart.getStyleManager().setxAxisLogarithmic(true); // Customize Chart chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java index b5a91530a5987320a84a56982dd23515e5d22f7d..9ba2412008ee441136d3346abb1996b68d872740 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/Axis.java @@ -203,7 +203,7 @@ public class Axis implements ChartPart { } int width = (int) (getChart().getWidth() - axisPair.getyAxis().getBounds().getWidth() - chartLegendWidth - (getChart().getStyleManager().isLegendVisible() ? 3 : 2) - * getChart().getStyleManager().getChartPadding()); + * getChart().getStyleManager().getChartPadding() - getChart().getStyleManager().getPlotPadding()); int height = this.getSizeHint(); Rectangle xAxisRectangle = new Rectangle(xOffset, yOffset, width, height); this.paintZone = xAxisRectangle; diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java index 385db6db7ce7a667a15263bbc2bdc8d81813d59e..dc677a4d341048d5c603e0ae2f5995b801ae110d 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTick.java @@ -88,11 +88,11 @@ public class AxisTick implements ChartPart { gridStep = new BarChartAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart()); - } else if (axis.getDirection() == Axis.Direction.X && getChart().getStyleManager().isXAxisLogarithmic() && axis.getAxisType() != AxisType.Date) { + } else if (axis.getDirection() == Axis.Direction.X && getChart().getStyleManager().isxAxisLogarithmic() && axis.getAxisType() != AxisType.Date) { gridStep = new LogarithmicAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getStyleManager()); - } else if (axis.getDirection() == Axis.Direction.Y && getChart().getStyleManager().isYAxisLogarithmic() && axis.getAxisType() != AxisType.Date) { + } else if (axis.getDirection() == Axis.Direction.Y && getChart().getStyleManager().isyAxisLogarithmic() && axis.getAxisType() != AxisType.Date) { gridStep = new LogarithmicAxisTickCalculator(axis.getDirection(), workingSpace, axis.getMin(), axis.getMax(), getChart().getStyleManager()); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentLineChart.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentLineChart.java index a7494d39838c4e4ea3870112b09bb12d8d1a4472..2fc6bfc617a1e9894726159abc38f8f49b0e1f59 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentLineChart.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/PlotContentLineChart.java @@ -64,14 +64,14 @@ public class PlotContentLineChart extends PlotContent { Collection<?> xData = series.getxData(); BigDecimal xMin = getChart().getAxisPair().getxAxis().getMin(); BigDecimal xMax = getChart().getAxisPair().getxAxis().getMax(); - if (getChart().getStyleManager().isXAxisLogarithmic()) { + if (getChart().getStyleManager().isxAxisLogarithmic()) { xMin = new BigDecimal(Math.log10(xMin.doubleValue())); xMax = new BigDecimal(Math.log10(xMax.doubleValue())); } Collection<Number> yData = series.getyData(); BigDecimal yMin = getChart().getAxisPair().getyAxis().getMin(); BigDecimal yMax = getChart().getAxisPair().getyAxis().getMax(); - if (getChart().getStyleManager().isYAxisLogarithmic()) { + if (getChart().getStyleManager().isyAxisLogarithmic()) { yMin = new BigDecimal(Math.log10(yMin.doubleValue())); yMax = new BigDecimal(Math.log10(yMax.doubleValue())); } @@ -97,13 +97,13 @@ public class PlotContentLineChart extends PlotContent { // System.out.println(x); } - if (getChart().getStyleManager().isXAxisLogarithmic()) { + if (getChart().getStyleManager().isxAxisLogarithmic()) { x = new BigDecimal(Math.log10(x.doubleValue())); } BigDecimal y = new BigDecimal(yItr.next().doubleValue()); - if (getChart().getStyleManager().isYAxisLogarithmic()) { + if (getChart().getStyleManager().isyAxisLogarithmic()) { y = new BigDecimal(Math.log10(y.doubleValue())); } diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateFormatter.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateFormatter.java index e94786e923b9aaa54b1d86a7bce4c95a9698c88e..6f03f330b818a6911eee3ba95745d093076b1955 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateFormatter.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/axistickcalculator/DateFormatter.java @@ -90,21 +90,25 @@ public class DateFormatter { String datePattern; - // intelligently set date pattern if none is given - if (timeUnit == MILLIS_SCALE) { - datePattern = "ss.SSS"; - } else if (timeUnit == SEC_SCALE) { - datePattern = "mm:ss"; - } else if (timeUnit == MIN_SCALE) { - datePattern = "HH:mm"; - } else if (timeUnit == HOUR_SCALE) { - datePattern = "dd-HH"; - } else if (timeUnit == DAY_SCALE) { - datePattern = "MM-dd"; - } else if (timeUnit == MONTH_SCALE) { - datePattern = "yyyy-MM"; + if (styleManager.getDatePattern() == null) { + // intelligently set date pattern if none is given + if (timeUnit == MILLIS_SCALE) { + datePattern = "ss.SSS"; + } else if (timeUnit == SEC_SCALE) { + datePattern = "mm:ss"; + } else if (timeUnit == MIN_SCALE) { + datePattern = "HH:mm"; + } else if (timeUnit == HOUR_SCALE) { + datePattern = "dd-HH"; + } else if (timeUnit == DAY_SCALE) { + datePattern = "MM-dd"; + } else if (timeUnit == MONTH_SCALE) { + datePattern = "yyyy-MM"; + } else { + datePattern = "yyyy"; + } } else { - datePattern = "yyyy"; + datePattern = styleManager.getDatePattern(); } SimpleDateFormat simpleDateformat = new SimpleDateFormat(datePattern, styleManager.getLocale()); diff --git a/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java b/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java index 5e8a2b3c1b0c7d185e3ef94f1dbf4c81be864cae..9347cac4393c6689f3e60ca4edc992e46c78c17a 100644 --- a/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java +++ b/xchart/src/main/java/com/xeiam/xchart/style/StyleManager.java @@ -166,7 +166,7 @@ public class StyleManager { errorBarsColor = theme.getErrorBarsColor(); // Formatting //////////////////////////////// - datePattern = "HHmmss"; + datePattern = null; // if not null, this override pattern will be used locale = Locale.getDefault(); timezone = TimeZone.getDefault(); normalDecimalPattern = "#.####"; @@ -656,14 +656,14 @@ public class StyleManager { /** * sets the X-Axis to be rendered with a logarithmic scale or not * - * @param isXAxisLogarithmic + * @param isxAxisLogarithmic */ - public void setXAxisLogarithmic(boolean isXAxisLogarithmic) { + public void setxAxisLogarithmic(boolean isxAxisLogarithmic) { - this.isXAxisLogarithmic = isXAxisLogarithmic; + this.isXAxisLogarithmic = isxAxisLogarithmic; } - public boolean isXAxisLogarithmic() { + public boolean isxAxisLogarithmic() { return isXAxisLogarithmic; } @@ -671,14 +671,14 @@ public class StyleManager { /** * sets the Y-Axis to be rendered with a logarithmic scale or not * - * @param isYAxisLogarithmic + * @param isyAxisLogarithmic */ - public void setYAxisLogarithmic(boolean isYAxisLogarithmic) { + public void setyAxisLogarithmic(boolean isyAxisLogarithmic) { - this.isYAxisLogarithmic = isYAxisLogarithmic; + this.isYAxisLogarithmic = isyAxisLogarithmic; } - public boolean isYAxisLogarithmic() { + public boolean isyAxisLogarithmic() { return isYAxisLogarithmic; }