Getting Started

This website explain how to use Jzy3D framework to build 3D charts for Java applications.

You will find 3 main sections

  • This Getting Started page providing code samples to draw your first 3D and 2D charts in Java. They are intended for any developer willing to get started in less than 5 minutes.
  • The User Guide chapters explaining the features of the framework. All code samples demonstrating these features can be purchased here.
  • The Developer Guide helps understand the internal architecture of the framework to help developers improving it.

Configure dependencies

Jzy3D can be retrieved with Maven. We here describe what your pom.xml file should contain to get started

Add reference to the Maven repository

The repositories definition must be located under the project tag

<project>
  ...
  <repositories>
    <repository>
      <id>jzy3d-snapshots</id>
      <name>Jzy3d Snapshots</name>
      <url>https://maven.jzy3d.org/snapshots/</url>
    </repository>
    <repository>
      <id>jzy3d-releases</id>
      <name>Jzy3d Releases</name>
      <url>https://maven.jzy3d.org/releases/</url>
    </repository>
  </repositories>
<project>

Add a reference to all artifacts

<dependencies>
  <dependency>
    <groupId>org.jzy3d</groupId>
    <artifactId>jzy3d-everything</artifactId>
    <version>2.1.1-SNAPSHOT</version>
  </dependency>
</dependencies>

Add a reference to native libraries

If you only want to use traditional GPU rendering with JOGL, you will have to define it per target windowing toolkit

For native OpenGL in AWT

<dependency>
    <groupId>org.jzy3d</groupId>
    <artifactId>jzy3d-native-jogl-awt</artifactId>
    <version>2.1.0</version>
</dependency>

For native OpenGL in Swing

<dependency>
    <groupId>org.jzy3d</groupId>
    <artifactId>jzy3d-native-jogl-swing</artifactId>
    <version>2.1.0</version>
</dependency>

For native OpenGL in SWT

<dependency>
    <groupId>org.jzy3d</groupId>
    <artifactId>jzy3d-native-jogl-swt</artifactId>
    <version>2.1.0</version>
</dependency>

Add a reference to non native libraries

If you only want to use fallback CPU rendering with EmulGL, you will have to define

<dependency>
    <groupId>org.jzy3d</groupId>
    <artifactId>jzy3d-emul-gl-awt</artifactId>
    <version>2.1.0</version>
</dependency>

Create your first charts

A 3D surface chart

This example can be found in the API tutorial module.

import org.jzy3d.chart.factories.AWTChartFactory;
import org.jzy3d.chart.factories.IChartFactory;
import org.jzy3d.colors.Color;
import org.jzy3d.colors.ColorMapper;
import org.jzy3d.colors.colormaps.ColorMapRainbow;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.builder.Func3D;
import org.jzy3d.plot3d.builder.SurfaceBuilder;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.Quality;

public class SurfaceDemoAWT extends AWTAbstractAnalysis {
  public static void main(String[] args) {

    // Define a function to plot
    Func3D func = new Func3D((x, y) -> x * Math.sin(x * y));
    Range range = new Range(-3, 3);
    int steps = 80;

    // Create the object to represent the function over the given range.
    final Shape surface = new SurfaceBuilder().orthonormal(new OrthonormalGrid(range, steps), func);
    surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface, new Color(1, 1, 1, .5f)));
    surface.setFaceDisplayed(true);
    surface.setWireframeDisplayed(true);
    surface.setWireframeColor(Color.BLACK);

    // Create a chart
    IChartFactory f = new AWTChartFactory();
    Chart chart = f.newChart(Quality.Advanced().setHiDPIEnabled(true));
    chart.getScene().getGraph().add(surface);
    chart.open();
    chart.addMouse();

  }
}

scatter3D

A 3D scatter chart

This example can be found in the API tutorial module.

import java.util.Random;
import org.jzy3d.chart.factories.AWTChartFactory;
import org.jzy3d.chart.factories.AWTPainterFactory;
import org.jzy3d.chart.factories.IChartFactory;
import org.jzy3d.chart.factories.IPainterFactory;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Coord3d;
import org.jzy3d.plot3d.primitives.Scatter;
import org.jzy3d.plot3d.rendering.canvas.Quality;

import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;


public class ScatterDemoAWT  {
  public static void main(String[] args) {

    // Generate scatter data
    int size = 500000;
    float x;
    float y;
    float z;
    float a;

    Coord3d[] points = new Coord3d[size];
    Color[] colors = new Color[size];

    Random r = new Random();
    r.setSeed(0);

    for (int i = 0; i < size; i++) {
      x = r.nextFloat() - 0.5f;
      y = r.nextFloat() - 0.5f;
      z = r.nextFloat() - 0.5f;
      points[i] = new Coord3d(x, y, z);
      a = 0.25f;
      colors[i] = new Color(x, y, z, a);
    }

    // Create a drawable scatter
    Scatter scatter = new Scatter(points, colors);

    // Open and show chart
    Quality q = Quality.Advanced();
    IChartFactory f = new AWTChartFactory();
    Chart chart = f.newChart(q);
    chart.getScene().add(scatter);
    chart.open();
    chart.addMouse();
  }
}

scatter3D

A 2D surface chart

This example can be found in the API tutorial module.

import org.jzy3d.chart.Chart;
import org.jzy3d.chart.factories.AWTChartFactory;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.primitives.SampleGeom;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.Quality;

public class Surface2D_DemoAWT {
  public static void main(String[] args) throws Exception {
    Shape surface = SampleGeom.surface(new Range (-3, 1), new Range(-1, 3), 1);
    surface.setWireframeDisplayed(false);

    Chart chart = new AWTChartFactory().newChart(Quality.Advanced());
    chart.add(surface);
    chart.view2d();
    chart.open();
    chart.addMouse();
  }
}

surface2D

A 2D scatter chart

This example can be found in the API tutorial module.

The SampleGeom class allows generating data in a more compact way than in the 3D example.

import org.jzy3d.chart.Chart;
import org.jzy3d.chart.factories.AWTChartFactory;
import org.jzy3d.plot3d.primitives.SampleGeom;
import org.jzy3d.plot3d.rendering.canvas.Quality;

public class Scatter2D_DemoAWT {
  public static void main(String[] args)  {
    Chart chart = new AWTChartFactory().newChart(Quality.Advanced());
    chart.add(SampleGeom.scatter(20000, 2));
    chart.view2d();
    chart.open();
  }
}

scatter2D