Showing a simple graph with XChart as SVG or PDF
Code: "SimpleXChart.java". Programming language: Java
DMelt Version 3. Last modified: 04/03/2023. License: Free
https://datamelt.org/code/cache/SimpleXChart_5807.java
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
import org.knowm.xchart.BitmapEncoder;
import org.knowm.xchart.BitmapEncoder.BitmapFormat;
import org.knowm.xchart.VectorGraphicsEncoder;
import org.knowm.xchart.VectorGraphicsEncoder.VectorGraphicsFormat;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.XYSeries;
import org.knowm.xchart.style.markers.SeriesMarkers;
public class SimpleXChart {
public static void main(String[] args) throws Exception {
double[] yData = new double[] {2.0, 1.0, 0.0};
XYChart chart = new XYChart(500, 400);
chart.setTitle("Sample Chart");
chart.setXAxisTitle("X");
chart.setXAxisTitle("Y");
XYSeries series = chart.addSeries("y(x)", null, yData);
series.setMarker(SeriesMarkers.CIRCLE);
VectorGraphicsEncoder.saveVectorGraphic(chart, "./Sample_Chart", VectorGraphicsFormat.PDF);
VectorGraphicsEncoder.saveVectorGraphic(chart, "./Sample_Chart", VectorGraphicsFormat.SVG);
}
}