如何使用Jzy3d java 3d图表库?

时间:2011-11-08 09:03:41

标签: java charts jzy3d

有人可以给我一些关于如何使用jzy3d的基本例子吗? (源站点的示例不适合我工作)

我尝试了以下代码:

import org.jzy3d.chart.Chart;
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.Builder;
import org.jzy3d.plot3d.builder.Mapper;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;

public class Test {

    public static void main(String[] args) {

        JFrame frame = new JFrame();
        Chart chart = getChart();

        frame.add((javax.swing.JComponent) chart.getCanvas());

        frame.setSize(800, 800);
        frame.setLocationRelativeTo(null);
        frame.setTitle("test");
        frame.setVisible(true);
    }

    public static Chart getChart() {
        // Define a function to plot
        Mapper mapper = new Mapper() {
            public double f(double x, double y) {
                return 10 * Math.sin(x / 10) * Math.cos(y / 20) * x;
            }
        };

        // Define range and precision for the function to plot
        Range range = new Range(-150, 150);
        int steps = 50;

        // Create the object to represent the function over the given range.
        org.jzy3d.plot3d.primitives.Shape surface = (Shape) Builder.buildOrthonormal(new OrthonormalGrid(range, steps, range, steps), mapper);
        surface.setColorMapper(new ColorMapper(new ColorMapRainbow(), surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color(1, 1, 1, .5f)));
        surface.setWireframeDisplayed(true);
        surface.setWireframeColor(Color.BLACK);
        //surface.setFace(new ColorbarFace(surface));
        surface.setFaceDisplayed(true);
        //surface.setFace2dDisplayed(true); // opens a colorbar on the right part of the display

        // Create a chart
        Chart chart = new Chart();
        chart.getScene().getGraph().add(surface);
        return chart;
    }
}

但是当我尝试运行它时,我得到了那个例外:

  
    

线程“main”中的异常java.lang.UnsatisfiedLinkError:java.library.path中没有jogl

  

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

您应该将jogl.jar添加到类路径,将jogl.dll添加到PATH。
有关详细信息,请查看herehere

您可以阅读jogl 安装说明 here

答案 1 :(得分:0)

您应该运行JOGL本机库所在的程序或演示,即./bin/ {platform}。如果您正在使用Eclipse,请右键单击该项目,选择Propeties,Java Build Path,然后选择Libraries选项卡。在“jogl.jar - ...”项下,选择“本机库位置:(无)”,然后单击“编辑”按钮。按工作区...按钮,然后选择./bin/{platform}文件夹。

相关问题