散点图与连接点javafx

时间:2015-11-02 12:29:49

标签: javafx javafx-2 javafx-8 linechart

我正在学习用于创建GUI的javafx。我想实现X-Y NumberAxis的简单折线图。根据折线图的属性,连接数据点的线永远不会相交。

例如 - 假设数据点

    public string getRealPathFromUri (final Uri content)
    {
 // get intent from activity and added it here

    Uri uri;
    String stringUri;
    stringUri = uri.toString();
    }

折线图中这些点的输出是 - line chart](http://[![enter image description here] 1

其中应该是以下编辑的相同点的散点图输出图像 - enter image description here

有没有办法改变折线图的这种行为?或连接散点图的点

请注意,我将动态添加点,下限,两个轴的上限将不断变化。

1 个答案:

答案 0 :(得分:3)

关闭图表的sorting policy

lineChart.setAxisSortingPolicy(LineChart.SortingPolicy.NONE);

当我使用它时,我会得到这个漂亮的孩子的涂鸦。

mess

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;

public class LineChartSample extends Application {

    @Override public void start(Stage stage) {
        final NumberAxis xAxis = new NumberAxis();
        final NumberAxis yAxis = new NumberAxis();

        final LineChart<Number,Number> lineChart =
                new LineChart<>(xAxis, yAxis);

        XYChart.Series<Number, Number> series = new XYChart.Series<>();
        series.getData().addAll(
                new XYChart.Data<>(4, 24),
                new XYChart.Data<>(1, 23),
                new XYChart.Data<>(6, 36),
                new XYChart.Data<>(8, 45),
                new XYChart.Data<>(2, 14),
                new XYChart.Data<>(9, 43),
                new XYChart.Data<>(7, 22),
                new XYChart.Data<>(12, 25),
                new XYChart.Data<>(10, 17),
                new XYChart.Data<>(5, 34),
                new XYChart.Data<>(3, 15),
                new XYChart.Data<>(11, 29)
        );
        lineChart.setAxisSortingPolicy(LineChart.SortingPolicy.NONE);

        Scene scene  = new Scene(lineChart,800,600);
        lineChart.getData().add(series);
        lineChart.setLegendVisible(false);

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

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