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 45c335b6831701f0cd728bf4b5b03b9172a38c96..728f46b6d8a01aec7faac4e66caa136feab15c08 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 @@ -39,16 +39,14 @@ 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.LineChart03; -import com.xeiam.xchart.demo.charts.line.LineChart05; -import com.xeiam.xchart.demo.charts.line.LineChart06; -import com.xeiam.xchart.demo.charts.line.LineChart07; -import com.xeiam.xchart.demo.charts.line.LineChart08; import com.xeiam.xchart.demo.charts.line.LineChart09; import com.xeiam.xchart.demo.charts.line.LineChart10; -import com.xeiam.xchart.demo.charts.line.LineChart11; import com.xeiam.xchart.demo.charts.scatter.ScatterChart01; import com.xeiam.xchart.demo.charts.scatter.ScatterChart02; +import com.xeiam.xchart.demo.charts.scatter.ScatterChart03; +import com.xeiam.xchart.demo.charts.scatter.ScatterChart04; +import com.xeiam.xchart.demo.charts.theme.ThemeChart01; +import com.xeiam.xchart.demo.charts.theme.ThemeChart02; /** * Class containing all XChart example charts @@ -88,7 +86,7 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { JScrollPane treeView = new JScrollPane(tree); // Create Chart Panel - chartPanel = new XChartPanel(new LineChart01().getChart()); + chartPanel = new XChartPanel(new AreaChart01().getChart()); // Add the scroll panes to a split pane. splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); @@ -138,25 +136,10 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { category = new DefaultMutableTreeNode("Line Charts"); top.add(category); - chart = new DefaultMutableTreeNode(new ChartInfo("LineChart01 - Manual Data", new LineChart01().getChart())); + chart = new DefaultMutableTreeNode(new ChartInfo("LineChart01 - Logarithmic Y-Axis", new LineChart01().getChart())); category.add(chart); - chart = new DefaultMutableTreeNode(new ChartInfo("LineChart02 - Customized series style", new LineChart02().getChart())); - category.add(chart); - - chart = new DefaultMutableTreeNode(new ChartInfo("LineChart03 - Multiple curves on one Chart", new LineChart03().getChart())); - category.add(chart); - - chart = new DefaultMutableTreeNode(new ChartInfo("LineChart05 - Vertical and horizontal lines", new LineChart05().getChart())); - category.add(chart); - - chart = new DefaultMutableTreeNode(new ChartInfo("LineChart06 - Single point", new LineChart06().getChart())); - category.add(chart); - - chart = new DefaultMutableTreeNode(new ChartInfo("LineChart07 - Longs as X-Axis data", new LineChart07().getChart())); - category.add(chart); - - chart = new DefaultMutableTreeNode(new ChartInfo("LineChart08 - Error bars", new LineChart08().getChart())); + 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())); @@ -165,18 +148,22 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { chart = new DefaultMutableTreeNode(new ChartInfo("LineChart10 - Plots Hundreds of Series on One Plot", new LineChart10().getChart())); category.add(chart); - chart = new DefaultMutableTreeNode(new ChartInfo("LineChart11 - Using ChartBuilder to Make a Chart", new LineChart11().getChart())); - category.add(chart); - // Scatter category category = new DefaultMutableTreeNode("Scatter Charts"); top.add(category); chart = new DefaultMutableTreeNode(new ChartInfo("ScatterChart01 - Gaussian Blob", new ScatterChart01().getChart())); category.add(chart); + chart = new DefaultMutableTreeNode(new ChartInfo("ScatterChart02 - Logarithmic Data", new ScatterChart02().getChart())); category.add(chart); + chart = new DefaultMutableTreeNode(new ChartInfo("ScatterChart03 - Single point", new ScatterChart03().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("ScatterChart04 - Error Bars", new ScatterChart04().getChart())); + category.add(chart); + // Area category category = new DefaultMutableTreeNode("Area Charts"); top.add(category); @@ -184,6 +171,16 @@ public class XChartDemo extends JPanel implements TreeSelectionListener { chart = new DefaultMutableTreeNode(new ChartInfo("AreaChart01 - 3-Series", new AreaChart01().getChart())); category.add(chart); + // Theme category + category = new DefaultMutableTreeNode("Chart Themes"); + top.add(category); + + chart = new DefaultMutableTreeNode(new ChartInfo("ThemeChart01 - Default XChart Theme", new ThemeChart01().getChart())); + category.add(chart); + + chart = new DefaultMutableTreeNode(new ChartInfo("ThemeChart01 - GGPlot2 Theme", new ThemeChart02().getChart())); + category.add(chart); + // Date category category = new DefaultMutableTreeNode("Date Charts"); top.add(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 2c40b189987e4f112096ee33e1f51a48b7e404e2..8ecbbf73b9d99934e30c0fd388c0ec8e271c7126 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 @@ -15,24 +15,24 @@ */ package com.xeiam.xchart.demo.charts.line; -import java.util.Arrays; -import java.util.Collection; +import java.util.ArrayList; +import java.util.List; import com.xeiam.xchart.Chart; +import com.xeiam.xchart.ChartBuilder; import com.xeiam.xchart.Series; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.demo.charts.ExampleChart; -import com.xeiam.xchart.style.SeriesMarker; +import com.xeiam.xchart.style.StyleManager.LegendPosition; /** - * Hardcoded Data + * Logarithmic Y-Axis * <p> - * Demonstrates the following: + * * Demonstrates the following: * <ul> - * <li>Series data hardcoded, perhaps copied from elsewhere - * <li>LineChart without series markers - * - * @author timmolter + * <li>Logarithmic Y-Axis + * <li>Building a Chart with ChartBuilder + * <li>Place legend at Inside-NW position */ public class LineChart01 implements ExampleChart { @@ -46,49 +46,24 @@ public class LineChart01 implements ExampleChart { @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, - 0.43815334002193185, 0.4524135262330098, 0.46488824294412573, 0.4755282581475768, 0.4842915805643156, 0.49114362536434436, 0.49605735065723894, 0.4990133642141358, 0.5, 0.4990133642141358, - 0.4960573506572389, 0.4911436253643443, 0.4842915805643155, 0.4755282581475767, 0.46488824294412556, 0.4524135262330097, 0.4381533400219316, 0.42216396275100737, 0.4045084971874735, - 0.38525662138789435, 0.36448431371070544, 0.342273552964344, 0.31871199487434443, 0.29389262614623607, 0.2679133974894978, 0.24087683705085702, 0.21288964578253586, 0.18406227634233846, - 0.15450849718747314, 0.12434494358242676, 0.09369065729286163, 0.0626666167821514, 0.0313952597646559, -6.049014748177263E-16, -0.03139525976465733, -0.06266661678215281, - -0.09369065729286304, -0.12434494358242815, -0.1545084971874745, -0.1840622763423398, -0.21288964578253713, -0.24087683705085847, -0.26791339748949894, -0.29389262614623723, - -0.31871199487434554, -0.342273552964345, -0.3644843137107064, -0.38525662138789524, -0.40450849718747445, -0.42216396275100815, -0.43815334002193224, -0.45241352623301023, - -0.46488824294412606, -0.47552825814757715, -0.4842915805643158, -0.4911436253643446, -0.49605735065723905, -0.4990133642141359, -0.5, -0.49901336421413567, -0.49605735065723877, - -0.491143625364344, -0.4842915805643152, -0.47552825814757643, -0.4648882429441252, -0.4524135262330092, -0.438153340021931, -0.42216396275100676, -0.4045084971874727, -0.3852566213878937, - -0.36448431371070455, -0.3422735529643432, -0.31871199487434343, -0.29389262614623524, -0.26791339748949666, -0.2408768370508561, -0.2128896457825349, -0.18406227634233727, - -0.15450849718747214, -0.12434494358242552, -0.0936906572928606, -0.06266661678215013, -0.03139525976465486, 2.097981369335578E-15 }; - - Collection<Number> xData = Arrays.asList(xDataArray); - - Number[] yDataArray = new Number[] { 0.0, 1.5702142318133935E-5, 3.13688735543879E-5, 4.703341403158832E-5, 6.303295245179154E-5, 8.092859563778825E-5, 1.0594882618710001E-4, - 1.558236372723155E-4, 2.7329707705089635E-4, 5.199254519985949E-4, 9.014386029378818E-4, 0.0013306621873173169, 0.0017306604364273927, 0.0020715324272834947, 0.0023569051679597362, - 0.0025927070538466638, 0.0027886026991513404, 0.002952502529028644, 0.0030880047369627284, 0.0032003236220216743, 0.003291666404197254, 0.0033648801628904596, 0.003421046591348078, - 0.0034608642835927588, 0.0034853783634585696, 0.0034948715689020367, 0.0034897171052496183, 0.0034701613190169425, 0.0034365427075935128, 0.003389087289131133, 0.0033280335272856142, - 0.003253771246701497, 0.0031666186473881487, 0.00306689011690467, 0.0029550247059562454, 0.0028314794027288065, 0.0026967349463042378, 0.002551357830616439, 0.002395898998210993, - 0.0022309713675244328, 0.002057244774600177, 0.0018753905860785436, 0.0016861342273231793, 0.0014902252697364343, 0.0012884341340577633, 0.0010815578443189703, 8.704131639000351E-4, - 6.558335341671071E-4, 4.3866560733456445E-4, 2.19766427583401E-4, -4.234301271122286E-18, -2.1976644564027456E-4, -4.3866524602280996E-4, -6.558321784509378E-4, -8.703966842877769E-4, - -0.0010814873042787273, -0.0012881467574255387, -0.0014891336787390336, -0.0016823672042564418, -0.0018627630869467102, -0.0020181202111633698, -0.002119632929541168, -0.002114609338758541, - -0.0019593967275554746, -0.0016730082089855846, -0.0013440006960966345, -0.0010483972455089105, -8.149512680002023E-4, -6.433644138995512E-4, -5.209373197845712E-4, -4.34946817866983E-4, - -3.7661743777884615E-4, -3.3739281674167966E-4, -3.099970594128415E-4, -2.9070472170425525E-4, -2.77636367693098E-4, -2.68102425931983E-4, -2.6019714020176945E-4, -2.536145792301906E-4, - -2.4744573769866404E-4, -2.4122358912925663E-4, -2.3473774775902484E-4, -2.2772135357722773E-4, -2.2006305955750752E-4, -2.1171197663128998E-4, -2.026763153011749E-4, -1.928814887412768E-4, - -1.8242620113215842E-4, -1.712818057089484E-4, -1.5947175495155755E-4, -1.470534737044005E-4, -1.340464949116753E-4, -1.2051929111759324E-4, -1.0651565202537847E-4, -9.209212285608304E-5, - -7.730521584738858E-5, -6.221344753211741E-5, -4.687672566856378E-5, -3.135450711247751E-5, -1.5708413280955366E-5, 1.0498035802487025E-18 }; - - Collection<Number> yData = Arrays.asList(yDataArray); + // generates Log data + List<Number> xData1 = new ArrayList<Number>(); + List<Number> yData1 = new ArrayList<Number>(); + for (int i = 0; i <= 10; i++) { + xData1.add(i); + yData1.add(Math.pow(10, i)); + } // Create Chart - Chart chart = new Chart(800, 600); + Chart chart = new ChartBuilder().width(800).height(600).build(); // Customize Chart - chart.setChartTitle("LineChart01"); chart.getStyleManager().setChartTitleVisible(false); - chart.getStyleManager().setLegendVisible(false); + chart.getStyleManager().setLegendPosition(LegendPosition.InsideNW); + chart.getStyleManager().setYAxisLogarithmic(true); - // Series 1 - Series series1 = chart.addSeries("data", xData, yData); - series1.setMarker(SeriesMarker.NONE); + // Series + Series series = chart.addSeries("10^x", xData1, yData1); return chart; } diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java index 19c78112588c0ed61e90c8346f326f7a0aecd074..141710eff9da4aa7c1822588b1446ec96b0c1429 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart02.java @@ -31,8 +31,7 @@ import com.xeiam.xchart.style.SeriesMarker; * <p> * * Demonstrates the following: * <ul> - * <li>Customizing the series style properties</li> - * </ul> + * <li>Customizing the series style properties */ public class LineChart02 implements ExampleChart { diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart07.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart07.java deleted file mode 100644 index e1c397588253a50fb72498320d155ed103fa4b76..0000000000000000000000000000000000000000 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart07.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 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.charts.line; - -import java.util.Arrays; -import java.util.Collection; - -import com.xeiam.xchart.Chart; -import com.xeiam.xchart.SwingWrapper; -import com.xeiam.xchart.demo.charts.ExampleChart; - -/** - * Longs as X-Axis data - */ -public class LineChart07 implements ExampleChart { - - public static void main(String[] args) { - - ExampleChart exampleChart = new LineChart07(); - 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(800, 600); - chart.setChartTitle("LineChart07"); - chart.setXAxisTitle("X"); - chart.setYAxisTitle("Y"); - chart.addSeries("y(x)", xData, yData); - - return chart; - } - -} diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart11.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart11.java deleted file mode 100644 index f2b3ba564d831ede9bce125855d265f75ea15cf0..0000000000000000000000000000000000000000 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart11.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright 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.charts.line; - -import com.xeiam.xchart.Chart; -import com.xeiam.xchart.ChartBuilder; -import com.xeiam.xchart.SwingWrapper; -import com.xeiam.xchart.demo.charts.ExampleChart; - -/** - * Using ChartBuilder to Make a Chart - */ -public class LineChart11 implements ExampleChart { - - public static void main(String[] args) { - - ExampleChart exampleChart = new LineChart11(); - Chart chart = exampleChart.getChart(); - new SwingWrapper(chart).displayChart(); - } - - @Override - public Chart getChart() { - - // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).title("LineChart11").xAxisTitle("X").yAxisTitle("Y").build(); - chart.addSeries("x", new double[] { 1, 2, 5, 7 }, new double[] { -3, 6, 9, 0 }); - - return chart; - } -} diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart06.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart03.java similarity index 85% rename from xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart06.java rename to xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart03.java index a49c0b171065ceec3e3314c51d34cd9975762793..a738bb969a640f8cbf3f3031385c603989215603 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart06.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart03.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.demo.charts.line; +package com.xeiam.xchart.demo.charts.scatter; import com.xeiam.xchart.Chart; import com.xeiam.xchart.SwingWrapper; @@ -22,11 +22,11 @@ import com.xeiam.xchart.demo.charts.ExampleChart; /** * Single point */ -public class LineChart06 implements ExampleChart { +public class ScatterChart03 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new LineChart06(); + ExampleChart exampleChart = new ScatterChart03(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } @@ -38,7 +38,7 @@ public class LineChart06 implements ExampleChart { Chart chart = new Chart(800, 600); // Customize Chart - chart.setChartTitle("LineChart06"); + chart.setChartTitle("ScatterChart03"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart08.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart04.java similarity index 59% rename from xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart08.java rename to xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart04.java index 0191eee1d2012406d49d72a4f0d02dc3c5f5839c..d085db1f2f07779e2b12cb47cfc40cdc21b253af 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart08.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/scatter/ScatterChart04.java @@ -13,27 +13,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.demo.charts.line; +package com.xeiam.xchart.demo.charts.scatter; +import java.awt.Color; import java.util.ArrayList; -import java.util.Collection; +import java.util.List; import com.xeiam.xchart.Chart; +import com.xeiam.xchart.ChartBuilder; import com.xeiam.xchart.Series; import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.demo.charts.ExampleChart; -import com.xeiam.xchart.style.SeriesColor; -import com.xeiam.xchart.style.SeriesLineStyle; import com.xeiam.xchart.style.SeriesMarker; +import com.xeiam.xchart.style.StyleManager.ChartType; /** - * Error bars + * Error Bars + * <p> + * Demonstrates the following: + * <ul> + * <li>Error Bars + * <li>Using ChartBuilder to Make a Chart + * <li>List<Number> data sets + * <li>Setting Series Marker and Marker Color */ -public class LineChart08 implements ExampleChart { +public class ScatterChart04 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new LineChart08(); + ExampleChart exampleChart = new ScatterChart04(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } @@ -43,9 +51,9 @@ public class LineChart08 implements ExampleChart { // generates data int size = 10; - Collection<Number> xData1 = new ArrayList<Number>(); - Collection<Number> yData1 = new ArrayList<Number>(); - Collection<Number> errorBars = new ArrayList<Number>(); + List<Number> xData1 = new ArrayList<Number>(); + List<Number> yData1 = new ArrayList<Number>(); + List<Number> errorBars = new ArrayList<Number>(); for (int i = 0; i <= size; i++) { xData1.add(i); yData1.add(10 * Math.exp(-i)); @@ -53,19 +61,17 @@ public class LineChart08 implements ExampleChart { } // Create Chart - Chart chart = new Chart(800, 600); + Chart chart = new ChartBuilder().width(800).height(600).title("ScatterChart04").xAxisTitle("X").yAxisTitle("Y").chartType(ChartType.Scatter).build(); // Customize Chart chart.getStyleManager().setChartTitleVisible(false); chart.getStyleManager().setLegendVisible(false); chart.getStyleManager().setAxisTitlesVisible(false); - // Series 1 - Series series1 = chart.addSeries("10^(-x)", xData1, yData1, errorBars); - series1.setLineColor(SeriesColor.PURPLE); - series1.setLineStyle(SeriesLineStyle.DASH_DASH); - series1.setMarkerColor(SeriesColor.GREEN); - series1.setMarker(SeriesMarker.SQUARE); + // Series + Series series = chart.addSeries("10^(-x)", xData1, yData1, errorBars); + series.setMarkerColor(Color.RED); + series.setMarker(SeriesMarker.SQUARE); return chart; } diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart01.java similarity index 87% rename from xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java rename to xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart01.java index d2e7afbb1af9c36ba54ee980b47da82c6de01149..53ee0a25f9cb545653863b34812658aa080c017c 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart03.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart01.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.demo.charts.line; +package com.xeiam.xchart.demo.charts.theme; import java.util.ArrayList; import java.util.Collection; @@ -23,13 +23,13 @@ import com.xeiam.xchart.SwingWrapper; import com.xeiam.xchart.demo.charts.ExampleChart; /** - * Multiple curves on one Chart + * Default XChart Theme */ -public class LineChart03 implements ExampleChart { +public class ThemeChart01 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new LineChart03(); + ExampleChart exampleChart = new ThemeChart01(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } @@ -52,7 +52,7 @@ public class LineChart03 implements ExampleChart { } // Customize Chart - chart.setChartTitle("LineChart03"); + chart.setChartTitle("ThemeChart01"); chart.setXAxisTitle("X"); chart.setYAxisTitle("Y"); diff --git a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart05.java b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart02.java similarity index 75% rename from xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart05.java rename to xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart02.java index b8abf2220014144cfa05b035655159479dcc8055..1d0145407d356f24c0fd3cd145eac58aa6f1dbc8 100644 --- a/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/line/LineChart05.java +++ b/xchart-demo/src/main/java/com/xeiam/xchart/demo/charts/theme/ThemeChart02.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.xeiam.xchart.demo.charts.line; +package com.xeiam.xchart.demo.charts.theme; import com.xeiam.xchart.Chart; import com.xeiam.xchart.ChartBuilder; @@ -26,15 +26,15 @@ import com.xeiam.xchart.style.theme.GGPlot2Theme; * <p> * Demonstrates the following: * <ul> - * <li>Building a Chart with ChartBuilder</li> - * <li>Applying the GGPlot2 Theme to the Chart</li> - * </ul> + * <li>Building a Chart with ChartBuilder + * <li>Applying the GGPlot2 Theme to the Chart + * <li>Vertical and Horizontal Lines */ -public class LineChart05 implements ExampleChart { +public class ThemeChart02 implements ExampleChart { public static void main(String[] args) { - ExampleChart exampleChart = new LineChart05(); + ExampleChart exampleChart = new ThemeChart02(); Chart chart = exampleChart.getChart(); new SwingWrapper(chart).displayChart(); } @@ -43,14 +43,7 @@ public class LineChart05 implements ExampleChart { public Chart getChart() { // Create Chart - Chart chart = new ChartBuilder().width(800).height(600).theme(new GGPlot2Theme()).build(); - - // new LineChart(800, 600); - - // Customize Chart - chart.setChartTitle("LineChart05"); - chart.setXAxisTitle("X"); - chart.setYAxisTitle("Y"); + Chart chart = new ChartBuilder().width(800).height(600).theme(new GGPlot2Theme()).title("ThemeChart02").xAxisTitle("X").yAxisTitle("Y").build(); chart.addSeries("vertical", new double[] { 1, 1 }, new double[] { -10, 10 }); chart.addSeries("horizontal", new double[] { -10, 10 }, new double[] { 0, 0 }); diff --git a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java index c40585e819a95031f701c22843a556de42a60c09..75cb3f685b7855bc1d06bad94252fc9612d9132a 100644 --- a/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java +++ b/xchart/src/main/java/com/xeiam/xchart/internal/chartpart/AxisTickLabels.java @@ -68,14 +68,16 @@ public class AxisTickLabels implements ChartPart { // System.out.println(tickLabel); int tickLocation = axisTick.getTickLocations().get(i); - FontRenderContext frc = g.getFontRenderContext(); - // TextLayout layout = new TextLayout(tickLabel, font, new FontRenderContext(null, true, false)); - TextLayout layout = new TextLayout(tickLabel, getChart().getStyleManager().getAxisTickLabelsFont(), frc); - Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0); - layout.draw(g, xOffset, (int) (yOffset + axisTick.getAxis().getPaintZone().getHeight() - tickLocation + tickLabelBounds.getHeight() / 2.0)); - - if (tickLabelBounds.getWidth() > maxTickLabelWidth) { - maxTickLabelWidth = (int) tickLabelBounds.getWidth(); + if (tickLabel != null) { // some are null for logarithmic axes + FontRenderContext frc = g.getFontRenderContext(); + // TextLayout layout = new TextLayout(tickLabel, font, new FontRenderContext(null, true, false)); + TextLayout layout = new TextLayout(tickLabel, getChart().getStyleManager().getAxisTickLabelsFont(), frc); + Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0); + layout.draw(g, xOffset, (int) (yOffset + axisTick.getAxis().getPaintZone().getHeight() - tickLocation + tickLabelBounds.getHeight() / 2.0)); + + if (tickLabelBounds.getWidth() > maxTickLabelWidth) { + maxTickLabelWidth = (int) tickLabelBounds.getWidth(); + } } } @@ -94,8 +96,8 @@ public class AxisTickLabels implements ChartPart { String tickLabel = axisTick.getTickLabels().get(i); int tickLocation = axisTick.getTickLocations().get(i); - FontRenderContext frc = g.getFontRenderContext(); if (tickLabel != null) { // some are null for logarithmic axes + FontRenderContext frc = g.getFontRenderContext(); TextLayout layout = new TextLayout(tickLabel, getChart().getStyleManager().getAxisTickLabelsFont(), frc); Rectangle tickLabelBounds = layout.getPixelBounds(null, 0, 0); layout.draw(g, (int) (xOffset + tickLocation - tickLabelBounds.getWidth() / 2.0), yOffset);