Javafx Linechart不绘制圆圈?

 2023-02-15    420  

问题描述

此图表显示了问题:

问题

我有javafx程序可以计算数据并绘制图表,但是为什么点未正确连接?我尝试了很多事情,甚至创建了两个单独的系列,但它不起作用.

public void createScatterChart(){
    final NumberAxis xAxis = new NumberAxis();
    final NumberAxis yAxis = new NumberAxis();

    final SmoothedChart<Number,Number> smoothedChart = new SmoothedChart<>(xAxis, yAxis);

    XYChart.Series series1 = new XYChart.Series();
    XYChart.Series series2 = new XYChart.Series();
    XYChart.Series series3 = new XYChart.Series();

    for(int i = 0 ; i < this.r.size() ; i ++)
    {
        series1.getData().add(new XYChart.Data(this.r.get(i) * Math.cos(Math.toRadians(this.nodes.get(i))),this.r.get(i) * Math.sin(Math.toRadians(this.nodes.get(i)))));
        //series2.getData().add(new XYChart.Data(this.r.get(i) * Math.cos(Math.toRadians(this.nodes.get(i) * this.xArray[i][0])),this.r.get(i) * Math.sin(Math.toRadians(this.nodes.get(i) * this.xArray[i][0]))));
    }


    smoothedChart.getData().add(series1);
    smoothedChart.getData().add(series2);
    Stage stage = new Stage();
    Scene scene  = new Scene(smoothedChart,800,600);

    stage.setScene(scene);
    stage.show();
}

推荐答案

研究了一个类似的问题在这里,该解决方案在其中呈现数据排序顺序.查看 href =” https://openjfx.io/javadoc/17/javafx.controls/javafx/javafx/scene/chart/chart/linechart.sortingpolicy.html#none”数据应以XYChart.dataProperty()列表定义的顺序保留.”

我必须将图表从我的SmoothChart更改为标准LineChart.

根据您的平滑方法,您可能会遇到所检查的一种立方样条形物件,在这里也发生在此处. jfreechart-fx .使用Bézier曲线的方法被添加在这里.

使用合成数据:

Javafx
 x_axis

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 * @see https://stackoverflow.com/a/72607616/230513
 * @see https://stackoverflow.com/a/2510048/230513
 */
public class ChartTest extends Application {

    private static final int N = 32;

    @Override
    public void start(Stage stage) {
        var xAxis = new NumberAxis();
        var yAxis = new NumberAxis();
        var series = new XYChart.Series();
        series.setName("Data");
        for (int i = 0; i <= N; i++) {
            var t = 2 * Math.PI * i / N;
            var x = Math.cos(t);
            var y = Math.sin(t);
            series.getData().add(new XYChart.Data(x, y));
        }
        var chart = new LineChart<Number, Number>(xAxis, yAxis);
        chart.getData().add(series);
        ObservableList<LineChart.SortingPolicy> policies
            = FXCollections.observableArrayList(LineChart.SortingPolicy.values());
        var policy = new ChoiceBox<LineChart.SortingPolicy>(policies);
        policy.setTooltip(new Tooltip("Choose a data sorting policy."));
        policy.getSelectionModel().select(chart.getAxisSortingPolicy());
        chart.axisSortingPolicyProperty().bind(policy.valueProperty());
        Pane root = new StackPane(chart, policy);
        StackPane.setAlignment(policy, Pos.TOP_RIGHT);
        stage.setScene(new Scene(root));
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

以上所述是小编给大家介绍的Javafx Linechart不绘制圆圈?,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!

原文链接:https://77isp.com/post/33775.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。