Skip to content
Snippets Groups Projects
Commit 71490aed authored by Tim Molter's avatar Tim Molter
Browse files

minor example code clean up

parent e2a08275
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,7 @@ import org.knowm.xchart.internal.style.Styler.LegendPosition; ...@@ -34,7 +34,7 @@ import org.knowm.xchart.internal.style.Styler.LegendPosition;
* <li>All positive values * <li>All positive values
* <li>Single series * <li>Single series
* <li>Place legend at Inside-NW position * <li>Place legend at Inside-NW position
* <li>Bars touch X-Axis * <li>Bars span 100% allowed space
*/ */
public class BarChart01 implements ExampleChart { public class BarChart01 implements ExampleChart {
......
...@@ -39,6 +39,11 @@ import org.knowm.xchart.internal.style.lines.SeriesLines; ...@@ -39,6 +39,11 @@ import org.knowm.xchart.internal.style.lines.SeriesLines;
import org.knowm.xchart.internal.style.markers.SeriesMarkers; import org.knowm.xchart.internal.style.markers.SeriesMarkers;
/** /**
* Customized Chart
* <p>
* Demonstrates the following:
* <ul>
* <li>
* Extensive Chart Customization * Extensive Chart Customization
*/ */
public class LineChart03 implements ExampleChart { public class LineChart03 implements ExampleChart {
......
...@@ -50,15 +50,6 @@ public class ScatterChart01 implements ExampleChart { ...@@ -50,15 +50,6 @@ public class ScatterChart01 implements ExampleChart {
@Override @Override
public Chart getChart() { public Chart getChart() {
List<Double> xData = new LinkedList<Double>();
List<Double> yData = new LinkedList<Double>();
Random random = new Random();
int size = 1000;
for (int i = 0; i < size; i++) {
xData.add(random.nextGaussian() / 1000);
yData.add(-1000000 + random.nextGaussian());
}
// Create Chart // Create Chart
Chart_XY chart = new ChartBuilder_XY().width(800).height(600).build(); Chart_XY chart = new ChartBuilder_XY().width(800).height(600).build();
...@@ -69,6 +60,14 @@ public class ScatterChart01 implements ExampleChart { ...@@ -69,6 +60,14 @@ public class ScatterChart01 implements ExampleChart {
chart.getStyler().setMarkerSize(16); chart.getStyler().setMarkerSize(16);
// Series // Series
List<Double> xData = new LinkedList<Double>();
List<Double> yData = new LinkedList<Double>();
Random random = new Random();
int size = 1000;
for (int i = 0; i < size; i++) {
xData.add(random.nextGaussian() / 1000);
yData.add(-1000000 + random.nextGaussian());
}
chart.addSeries("Gaussian Blob", xData, yData); chart.addSeries("Gaussian Blob", xData, yData);
return chart; return chart;
......
...@@ -52,16 +52,6 @@ public class ScatterChart02 implements ExampleChart { ...@@ -52,16 +52,6 @@ public class ScatterChart02 implements ExampleChart {
@Override @Override
public Chart getChart() { public Chart getChart() {
List<Double> xData = new ArrayList<Double>();
List<Double> yData = new ArrayList<Double>();
Random random = new Random();
int size = 400;
for (int i = 0; i < size; i++) {
double nextRandom = random.nextDouble();
xData.add(Math.pow(10, nextRandom * 10));
yData.add(1000000000.0 + nextRandom);
}
// Create Chart // Create Chart
Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Logarithmic Data").build(); Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Logarithmic Data").build();
...@@ -71,6 +61,15 @@ public class ScatterChart02 implements ExampleChart { ...@@ -71,6 +61,15 @@ public class ScatterChart02 implements ExampleChart {
chart.getStyler().setLegendPosition(LegendPosition.InsideN); chart.getStyler().setLegendPosition(LegendPosition.InsideN);
// Series // Series
List<Double> xData = new ArrayList<Double>();
List<Double> yData = new ArrayList<Double>();
Random random = new Random();
int size = 400;
for (int i = 0; i < size; i++) {
double nextRandom = random.nextDouble();
xData.add(Math.pow(10, nextRandom * 10));
yData.add(1000000000.0 + nextRandom);
}
chart.addSeries("logarithmic data", xData, yData); chart.addSeries("logarithmic data", xData, yData);
return chart; return chart;
......
...@@ -18,6 +18,7 @@ package org.knowm.xchart.demo.charts.scatter; ...@@ -18,6 +18,7 @@ package org.knowm.xchart.demo.charts.scatter;
import org.knowm.xchart.ChartBuilder_XY; import org.knowm.xchart.ChartBuilder_XY;
import org.knowm.xchart.Chart_XY; import org.knowm.xchart.Chart_XY;
import org.knowm.xchart.Series_XY.ChartXYSeriesRenderStyle;
import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.demo.charts.ExampleChart;
import org.knowm.xchart.internal.chartpart.Chart; import org.knowm.xchart.internal.chartpart.Chart;
...@@ -44,6 +45,10 @@ public class ScatterChart03 implements ExampleChart { ...@@ -44,6 +45,10 @@ public class ScatterChart03 implements ExampleChart {
// Create Chart // Create Chart
Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Single Point").xAxisTitle("X").yAxisTitle("Y").build(); Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("Single Point").xAxisTitle("X").yAxisTitle("Y").build();
// Customize Chart
chart.getStyler().setDefaultSeriesRenderStyle(ChartXYSeriesRenderStyle.Scatter);
// Series
chart.addSeries("single point (1,1)", new double[] { 1 }, new double[] { 1 }); chart.addSeries("single point (1,1)", new double[] { 1 }, new double[] { 1 });
return chart; return chart;
......
...@@ -23,6 +23,7 @@ import java.util.List; ...@@ -23,6 +23,7 @@ import java.util.List;
import org.knowm.xchart.ChartBuilder_XY; import org.knowm.xchart.ChartBuilder_XY;
import org.knowm.xchart.Chart_XY; import org.knowm.xchart.Chart_XY;
import org.knowm.xchart.Series_XY; import org.knowm.xchart.Series_XY;
import org.knowm.xchart.Series_XY.ChartXYSeriesRenderStyle;
import org.knowm.xchart.SwingWrapper; import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.demo.charts.ExampleChart; import org.knowm.xchart.demo.charts.ExampleChart;
import org.knowm.xchart.internal.chartpart.Chart; import org.knowm.xchart.internal.chartpart.Chart;
...@@ -51,27 +52,26 @@ public class ScatterChart04 implements ExampleChart { ...@@ -51,27 +52,26 @@ public class ScatterChart04 implements ExampleChart {
@Override @Override
public Chart getChart() { public Chart getChart() {
// generates data
int size = 10;
List<Double> xData = new ArrayList<Double>();
List<Double> yData = new ArrayList<Double>();
List<Double> errorBars = new ArrayList<Double>();
for (int i = 0; i <= size; i++) {
xData.add(((double) i) / 1000000);
yData.add(10 * Math.exp(-i));
errorBars.add(Math.random() + .3);
}
// Create Chart // Create Chart
Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("ScatterChart04").xAxisTitle("X").yAxisTitle("Y").build(); Chart_XY chart = new ChartBuilder_XY().width(800).height(600).title("ScatterChart04").xAxisTitle("X").yAxisTitle("Y").build();
// Customize Chart // Customize Chart
chart.getStyler().setDefaultSeriesRenderStyle(ChartXYSeriesRenderStyle.Scatter);
chart.getStyler().setChartTitleVisible(false); chart.getStyler().setChartTitleVisible(false);
chart.getStyler().setLegendVisible(false); chart.getStyler().setLegendVisible(false);
chart.getStyler().setAxisTitlesVisible(false); chart.getStyler().setAxisTitlesVisible(false);
chart.getStyler().setXAxisDecimalPattern("0.0000000"); chart.getStyler().setXAxisDecimalPattern("0.0000000");
// Series // Series
int size = 10;
List<Double> xData = new ArrayList<Double>();
List<Double> yData = new ArrayList<Double>();
List<Double> errorBars = new ArrayList<Double>();
for (int i = 0; i <= size; i++) {
xData.add(((double) i) / 1000000);
yData.add(10 * Math.exp(-i));
errorBars.add(Math.random() + .3);
}
Series_XY series = chart.addSeries("10^(-x)", xData, yData, errorBars); Series_XY series = chart.addSeries("10^(-x)", xData, yData, errorBars);
series.setMarkerColor(Color.RED); series.setMarkerColor(Color.RED);
series.setMarker(SeriesMarkers.SQUARE); series.setMarker(SeriesMarkers.SQUARE);
......
...@@ -45,7 +45,7 @@ public class ThemeChart02 implements ExampleChart { ...@@ -45,7 +45,7 @@ public class ThemeChart02 implements ExampleChart {
public Chart getChart() { public Chart getChart() {
// Create Chart // Create Chart
Chart_XY chart = new ChartBuilder_XY().width(800).height(600).theme(ChartTheme.GGPlot2).title("GGPlot2 Theme").xAxisTitle("X").yAxisTitle("Y").build(); Chart_XY chart = new ChartBuilder_XY().width(800).height(600).theme(ChartTheme.Matlab).title("Matlab Theme").xAxisTitle("X").yAxisTitle("Y").build();
// Customize Chart // Customize Chart
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment