Area plot using series
Source code name: "xchart_area.java"
Programming language: Java
Topic: Plots/2D
DMelt Version 3. Last modified: 04/05/1977. License: Free
https://datamelt.org/code/cache/xchart_area_8942.java
To run this script using the DataMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.XYChartBuilder;
import org.knowm.xchart.XYSeries.XYSeriesRenderStyle;
import org.knowm.xchart.style.Styler.LegendPosition;
import org.knowm.xchart.VectorGraphicsEncoder;
import org.knowm.xchart.VectorGraphicsEncoder.VectorGraphicsFormat;
/**
* Area Chart with 3 series
*
* Demonstrates the following:
*
*
* Area Chart
* Place legend at Inside-NE position
*
ChartBuilder
*/
public class xchart_area {
public static void main(String[] args) throws Exception {
XYChart chart = getChart("Area");
new SwingWrapper(chart).displayChart();
VectorGraphicsEncoder.saveVectorGraphic(chart, "Area", VectorGraphicsFormat.PDF);
}
public static XYChart getChart(String name) {
XYChart chart =
new XYChartBuilder()
.width(800)
.height(600)
.title(name)
.xAxisTitle("X")
.yAxisTitle("Y")
.build();
chart.getStyler().setLegendPosition(LegendPosition.InsideNE);
chart.getStyler().setAxisTitlesVisible(false);
chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Area);
chart.addSeries("a", new double[] {0, 3, 5, 7, 9}, new double[] {-3, 5, 9, 6, 5});
chart.addSeries("b", new double[] {0, 2, 4, 6, 9}, new double[] {-1, 6, 4, 0, 4});
chart.addSeries("c", new double[] {0, 1, 3, 8, 9}, new double[] {-2, -1, 1, 0, 1});
return chart;
}
}