我正在尝试使用Java FX绘制带有x和y轴的多边形。我花了12个小时在网上搜索,没有运气!!! :(
多边形
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Polygon;
import javafx.stage.Stage;
public class PolygonExample extends Application {
@Override
public void start(Stage stage) {
//Creating a Polygon
Polygon polygon = new Polygon();
//Adding coordinates to the polygon
polygon.getPoints().addAll(new Double[]{
300.0, 50.0,
450.0, 150.0,
300.0, 250.0,
150.0, 150.0,
});
//Creating a Group object
Group root = new Group(polygon);
//Creating a scene object
Scene scene = new Scene(root, 600, 300);
//Setting title to the Stage
stage.setTitle("Drawing a Polygon");
//Adding scene to the stage
stage.setScene(scene);
//Displaying the contents of the stage
stage.show();
}
public static void main(String args[]){
launch(args);
}
}
我有这个但没有轴!
答案 0 :(得分:0)
您可以通过将polygon.getPoints().addAll()
语句替换为..
//Adding coordinates to the polygon
polygon.getPoints().addAll(new Double[]{
100.0, 250.0,
200.0, 100.0,
400.0, 100.0,
500.0, 250.0,
});
您的分数由于某种原因而被关闭,仅此而已。
尝试思考如何手工绘制。我只是挑选了最左边的点,并按照我在一张纸上用手画的顺序来添加点。
由以下代码显示:
答案 1 :(得分:0)
我们一直在使用Emxsys的“ JavaFX Chart Extensions”软件包。
从以下位置下载jfxchartext-1.1.zip
库
https://bitbucket.org/emxsys/javafx-chart-extensions/downloads/
它包含jar文件jfxchartext-1.1.jar
,您可以将其包含在项目中。
然后您可以使用其增强的图表之一-如EnhancedScatterChart
。
您可以添加一个XYPolygonAnnotation
并带有示例代码中所示的多边形坐标(请参见下面的链接-向下滚动至多边形注释部分。
https://bitbucket.org/emxsys/javafx-chart-extensions/wiki/XYAnnotation%20Extension
有关点坐标,您可以使用XYTextAnnotation
-请参阅页面底部。