Can someone please give me some extra basic example of how jzy3d should be used?
(The source site's examples don't seam to work for me)
I tried the following code:
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;
}
}
But when I try to run it, I get that exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jogl in java.library.path
Can anyone help?
You should add jogl.jar to classpath and jogl.dll to PATH.
For more info look here and here.
You can read jogl Installation Instructions here.
You should run your program or demo where the JOGL native libraries stand, i.e. ./bin/{platform}. If you are working with Eclipse, right click on the project, choose Propeties, Java Build Path then the Libraries tab. Under the item "jogl.jar - ..." select "Native library location: (None)" and click the Edit button. Press the Workspace... button and select the ./bin/{platform} folder.
Related
So, I've recently downloaded (via Maven) jzy3d library so that I can translate and improve an existing program of mine from JS to Java, and to get a handle on the new library I was trying some examples available on the library site but, as the title shows I keep getting the "Builder cannot be resolved" error.
I've tried to add the org.jzy3d.plot3d.builder.Builder import but also without success, as it returns a non used import alert.
This is my code:
package randomProjects;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.ChartLauncher;
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.Mapper;
import org.jzy3d.plot3d.builder.concrete.OrthonormalGrid;
import org.jzy3d.plot3d.primitives.Shape;
import org.jzy3d.plot3d.rendering.canvas.Quality;
public class SurfPlotTest_JZY3D {
public static void main(String[] args){
// 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 a surface drawing that function;
Shape surface = 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.setFaceDisplayed(true);
surface.setWireframeDisplayed(false);
surface.setWireframeColor(Color.BLACK);
// Create a chart and add the surface
Chart chart = new Chart(Quality.Advanced);
chart.getScene().getGraph().add(surface);
ChartLauncher.openChart(chart);
}
}
And this is the error message:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Builder cannot be resolved
The field Quality.Advanced is not visible
at randomProjects.SurfPlotTest_JZY3D.main(SurfPlotTest_JZY3D.java:30)
I also find important to mention that there is another error in the program at line #37, that I've tried fixing exchanging Quality.Advanced by Quality.Advanced(), but again, without any success what so ever.
A bit of an update in the hope of an answer
If I use the manually imported project files, also available in the library site, I don't get the builder error, but instead when compiling it returns the following error.
The project: org.jzy3d-0.9 which is referenced by the classpath, does not exist.
And this is the example code present in the project
package org.jzy3d.demos.surface;
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.controllers.keyboard.camera.CameraKeyController;
import org.jzy3d.colors.Color;
import org.jzy3d.colors.ColorMapper;
import org.jzy3d.colors.colormaps.ColorMapRainbow;
import org.jzy3d.demos.AbstractDemo;
import org.jzy3d.demos.DemoLauncher;
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;
import org.jzy3d.plot3d.rendering.canvas.Quality;
public class ColorWaveDemo extends AbstractDemo {
public static void main(String[] args) throws Exception {
DemoLauncher.openDemo(new ColorWaveDemo());
}
public ColorWaveDemo() {
}
#Override
public void init() {
// Define a function to plot
Mapper mapper = new Mapper() {
public double f(double x, double y) {
return x * Math.sin(x * y);
}
};
// Define range and precision for the function to plot
Range range = new Range(-3, 3);
int steps = 80;
// Create the object to represent the function over the given range.
final Shape surface = 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.setFaceDisplayed(true);
surface.setWireframeDisplayed(false);
// Create a chart
chart = new Chart(Quality.Advanced, getCanvasType());
chart.getScene().getGraph().add(surface);
chart.addController(new CameraKeyController());
}
}
Consider me a complete noob in importing libraries via Maven or otherwise, I'm doing all this to get a handle and learn how to, so I would appreciate a detailed answer. If needed I can also include my .pom file.
The tutorial page from the website is quite outdated. You may find easier to use the tutorials that are embedded in the library, e.g. this surface example.
The readme of this module should help as well.
So I was giving this code to run on Netbeans but I'm not sure what's wrong I'm doing, when I copy and past it to new project it keep giving me errors, I think I need to do something when I first create the project, naming most likely, but I can't figure out what's wrong.
The code is
Basically, my question is: if I give these two codes what you gonna do, step by step, to run them on NetBeans
//code one
package LineDrawing;
import java.awt.Color;
import java.awt.Graphics;
public class LiningPanel extends javax.swing.JPanel {
public LiningPanel() { }
public void paintComponent(Graphics g)
{
super.paintComponent(g);
int w = getWidth();
int h = getHeight();
double lines = 15.0;
for(int i = 0; i < lines; i++)
{
int w2 = (int)((i/lines)*w);
int h2 = (int)((i/lines)*h);
g.drawLine(0, h2, w2, h);
}
}
}
// code 2 //////////////////////////////////////////////////////////
package LineDrawing;
import javax.swing.JFrame;
public class LineDrawingTest {
public static void main(String[] args) {
JFrame application = new JFrame();
LiningPanel panel = new LiningPanel();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
application.add(panel);
application.setSize(300, 300);
application.setTitle("Lining Art");
application.setVisible(true);
}
}
It is difficult to figure unless you mention what exactly the error is. But based on the details provided (you have mentioned you are copying this to a new project and error is most likely related to naming), you might be copying this class to default package. You have to create 'LineDrawing' package and then create/copy your java file under this package. Alternatively, change the first line of your code :
package LineDrawing;
to reflect the correct package under which your java file is present.
I attempted to do a hello world application on jzy3d plotting library. I took the example from the website and when I run it I got the following error:
Exception in thread "main" java.lang.RuntimeException: No implemented
exception
Can anyone tell me what this means?
Here is the code for your reference:
import org.jzy3d.chart.Chart;
import org.jzy3d.chart.ChartLauncher;
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;
import org.jzy3d.plot3d.rendering.canvas.Quality;
public class HelloWorld {
public static void main(String[] args) {
// 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 a surface drawing that function
Shape surface = 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.setFaceDisplayed(true);
surface.setWireframeDisplayed(false);
surface.setWireframeColor(Color.BLACK);
// Create a chart and add the surface
Chart chart = new Chart(Quality.Advanced);
chart.getScene().getGraph().add(surface);
ChartLauncher.openChart(chart);
}
}
Error:
Exception in thread "main" java.lang.RuntimeException: No implemented
exception at
org.jzy3d.chart.factories.ChartComponentFactory.newFrame(ChartComponentFactory.java:148)
at org.jzy3d.chart.ChartLauncher.frame(ChartLauncher.java:82) at
org.jzy3d.chart.ChartLauncher.openChart(ChartLauncher.java:39) at
org.jzy3d.chart.ChartLauncher.openChart(ChartLauncher.java:33) at
org.jzy3d.chart.ChartLauncher.openChart(ChartLauncher.java:17) at
helloworld.HelloWorld.main(HelloWorld.java:77)
maybe this is a bug of the library itself, I had the same issue using jzy3d 0.9.1. Waiting for a new release, I solved the problem switching to the previous version jzy3d 0.9 that you can download from http://jzy3d.org/download-0.9.php . That worked for me, I hope it will work for you as well.
Best Regards
I am just trying to implement simple bar chart with vaadin chart.
just as tutorial in below rank, I wrote code.
Link : http://demo.vaadin.com/charts/#BasicBar
But when I trying to extend, since there was no such class 'AbstractVaadinChartExample', I just make that method public static.
below is what I have done.
I downloaded vaadin chart 1.1.5.jar
I put that in my vaadin 7 project
I did not edit original code except added a line in the last. layout.addComponent(BasicBar.getChart());
My BasicBar.java is just same with that upper link, but I did not extend anything and made getChart() method to 'public static'.
Now I got 'NoClassDefFoundError: com/google/gson/TypeAdapterFactory' error:-(
I can not understand, because I have done nothing with gson something.
My code like :
package org.owls.chart;
import java.util.ArrayList;
import java.util.List;
import com.vaadin.addon.charts.Chart;
import com.vaadin.addon.charts.model.ChartType;
import com.vaadin.addon.charts.model.Configuration;
import com.vaadin.addon.charts.model.HorizontalAlign;
import com.vaadin.addon.charts.model.Labels;
import com.vaadin.addon.charts.model.LayoutDirection;
import com.vaadin.addon.charts.model.Legend;
import com.vaadin.addon.charts.model.ListSeries;
import com.vaadin.addon.charts.model.PlotOptionsBar;
import com.vaadin.addon.charts.model.Title;
import com.vaadin.addon.charts.model.Tooltip;
import com.vaadin.addon.charts.model.VerticalAlign;
import com.vaadin.addon.charts.model.XAxis;
import com.vaadin.addon.charts.model.YAxis;
import com.vaadin.ui.Component;
public class BasicBar {
#SuppressWarnings({ "unchecked", "rawtypes" })
public static Component getChart () {
Chart chart = new Chart(ChartType.BAR);
Configuration config = chart.getConfiguration();
config.setTitle("basic chart");
config.setSubTitle("2014.02.14");
//X
XAxis xAxis = new XAxis();
xAxis.setCategories("A", "B", "C", "D", "E");
xAxis.setTitle("xTitle");
config.addxAxis(xAxis);
//Y
YAxis yAxis = new YAxis();
yAxis.setMin(0);
Title tile = new Title("y title");
tile.setVerticalAlign(VerticalAlign.HIGH);
yAxis.setTitle(tile);
config.addyAxis(yAxis);
Tooltip toolTip = new Tooltip();
//???
toolTip.setFormatter("this.series.name : + ': ' + this.y +' millions'");
config.setTooltip(toolTip);
//plot
PlotOptionsBar plot = new PlotOptionsBar();
//????
plot.setDataLabels(new Labels(true));
config.setPlotOptions(plot);
Legend legend = new Legend();
legend.setLayout(LayoutDirection.VERTICAL);
legend.setHorizontalAlign(HorizontalAlign.RIGHT);
legend.setVerticalAlign(VerticalAlign.TOP);
legend.setX(-100);
legend.setY(100);
legend.setFloating(true);
legend.setBorderWidth(1);
legend.setBackgroundColor("#FFFFFF");
legend.setShadow(true);
config.setLegend(legend);
config.disableCredits();
List series = new ArrayList();
series.add(new ListSeries("Year 1800", 107, 31, 635, 203, 2));
series.add(new ListSeries("Year 1900", 133, 156, 947, 408, 6));
series.add(new ListSeries("Year 2008", 973, 914, 4054, 732, 34));
config.setSeries(series);
chart.drawChart(config);
return chart;
}
}
How can I fix it?
Thanks :D
NoClassDefFoundError will arrive when your JAR is not referenced by the project. With the minor code change you have made, I don't think it will lead to the NoClassDefFoundError.
Can you please provide more info:
Is it simple Java project or web app?
You have added the JAR, but did you explicitely put it in the classpath using "Build classpath" in eclipse?
Without your minor changes, will the program runs successfully?
Sounds like you need this Jar loading: http://www.java2s.com/Code/Jar/g/Downloadgson221jar.htm
It's not mentioned in the Stripe setup guidelines, installing this Jar resolved this error message for me if anyone else encounters this problem.
Vaadin is GWT based so I suspect you are running a development server.
If so, add the gson path to you -Xbootclasspath
-Xbootclasspath/p:/somepath/libraries-master/appengine-java-sdk-1.9.48/lib/override/appengine-dev-jdk-overrides.jar:/p:/somepath/war/WEB-INF/lib/gson-2.2.4.jar
In Eclipse, look under run configurations --> Arguments --> VM Arguments
If you are launching the development server by Ant or another script, you will have to adjust the -Xbootclasspath there.
Am trying to create a NetBeans platform application. I created my own splash screen. The splash screen appears in the default about box.
But when I customized the about box, the default splash screen of NetBeans appears.
This is the location of my splash img.
branding/core/core.jar/org/netbeans/core/startup/splash.gif
This is how I have tried to access it and failed.
getClass().getResource("/org/netbeans/core/startup/splash.gif")
Can someone please help me in getting my splash img in the custom about box?
Yes, it is easy. Just right click to project - application, -> branding -> splash scree -> browse. ..
I am sorry for misunderstanding.
So it is easy too.
1) you modify App/important files/project properties add this line:
#for run
run.args=-J-Dnetbeans.mainclass=splah.CustomStartup --nosplash
#for run from IDE
run.args.extra=-J-Dnetbeans.mainclass=splah.CustomStartup --nosplash
2)create project JavaApplication splah and class CustomStartup, then build and copy the jar from dist to App/
package splah;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.lang.reflect.Method;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JWindow;
public class CustomStartup {
private static final String NB_MAIN_CLASS = "org.netbeans.core.startup.Main";
private static final int width = 500, height = 400;
public static void main(String[] args) throws Exception {
// do whatever you need here (e.g. show a custom login form)
System.out.println("Hello world! I am a custom startup class");
JDialog splash = new JDialog();
splash.setUndecorated(true);
//
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
splash.setBounds(width, height, (screenSize.width-width)/2, (screenSize.height-height)/2);
splash.setVisible(true);
// once you're done with that, hand control back to NetBeans
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
Class<?> mainClass = Class.forName(NB_MAIN_CLASS, true, classloader);
Object mainObject = mainClass.newInstance();
Method mainMethod = mainClass.getDeclaredMethod("main", new Class[]{String[].class});
mainMethod.invoke(mainObject, (Object) args);
splash.setVisible(false);
}
}
The Class is not from my head, I found it somewhere, but I do not remeber where.
Jirka