import java.awt.BorderLayout; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.ArrayList; import java.util.List; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.border.MatteBorder; import org.jzy3d.chart.Chart; import org.jzy3d.chart.controllers.keyboard.camera.AWTCameraKeyController; import org.jzy3d.chart.factories.SwingChartComponentFactory; import org.jzy3d.colors.ColorMapper; import org.jzy3d.colors.colormaps.ColorMapRBG; import org.jzy3d.maths.Coord3d; import org.jzy3d.plot3d.primitives.Point; import org.jzy3d.plot3d.primitives.Polygon; import org.jzy3d.plot3d.primitives.Shape; import org.jzy3d.plot3d.rendering.canvas.Quality; public class GraficaPerdidasPorEscenarios { public JPanel generarGrafica(double[][] distDataProp){ Listpolygons = new ArrayList (); final JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); // Use BorderLayout panel.setBounds(10, 10, 100, 100); for (int i = 0; i < distDataProp.length - 1; i++) { for (int j = 0; j < distDataProp[i].length - 1; j++) { Polygon polygon = new Polygon(); polygon.add(new Point(new Coord3d(i, j, distDataProp[i][j]))); polygon.add(new Point(new Coord3d(i, j + 1,distDataProp[i][j + 1]))); polygon.add(new Point(new Coord3d(i + 1, j + 1,distDataProp[i + 1][j + 1]))); polygon.add(new Point(new Coord3d(i + 1, j,distDataProp[i + 1][j]))); polygons.add(polygon); } } Shape surface = new Shape(polygons); surface.setColorMapper(new ColorMapper(new ColorMapRBG(), surface.getBounds().getZmin(), surface.getBounds().getZmax(),new org.jzy3d.colors.Color(1, 1, 1, 1f))); surface.setWireframeDisplayed(true); surface.setWireframeColor(org.jzy3d.colors.Color.BLACK); Chart chart = SwingChartComponentFactory.chart(Quality.Advanced); chart.getScene().getGraph().add(surface); chart.addController(new AWTCameraKeyController()); JComponent grafica = (JComponent)chart.getCanvas(); panel.add(grafica); return panel; } }
En este blog hay ideas sobre la informática en general. Programación, resolución de problemas y un poco de todo lo que concierne a este mundo de las computadoras...
viernes, 20 de diciembre de 2013
Uso jzy3d en JFrame y JPanel
Ejemplo de uso de jzy3d en un panel, en este caso utilicé versión jzy3d-api-0.9.2-SNAPSHOT para generar una gráfica de superficie.
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario