import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.XYChartBuilder;
import org.knowm.xchart.XYSeries;
import org.knowm.xchart.XYSeries.XYSeriesRenderStyle;
import org.knowm.xchart.style.Styler;
import org.knowm.xchart.style.markers.SeriesMarkers;
/**
* Gaussian Blob
*
* Demonstrates the following:
*
*
* - ChartType.Scatter
*
- Series data as a Set
*
- Setting marker size
*
- Formatting of negative numbers with large magnitude but small differences
*
- YAxis position on Right
*
- Cross type series marker
*/
public class xchart_scatter {
public static void main(String[] args) {
XYChart chart = getChart();
new SwingWrapper<>(chart).displayChart();
}
static public XYChart getChart() {
// Create Chart
XYChart chart = new XYChartBuilder().width(600).height(400).build();
// Customize Chart
chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Scatter);
chart.getStyler().setChartTitleVisible(false);
chart.getStyler().setLegendVisible(false);
chart.getStyler().setMarkerSize(16);
chart.getStyler().setYAxisGroupPosition(0, Styler.YAxisPosition.Right);
// Series
List
xData = new LinkedList();
List yData = new LinkedList();
Random random = new Random();
int size = 1000;
for (int i = 0; i < size; i++) {
xData.add(random.nextGaussian() / 1000);
yData.add(-1000000 + random.nextGaussian());
}
XYSeries series = chart.addSeries("Gaussian Blob", xData, yData);
series.setMarker(SeriesMarkers.CROSS);
return chart;
}
}