且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JavaFX实时LineChart与时间轴

更新时间:2023-02-26 17:52:00

=http://www.oracle.com/technetwork/java/javafx/samples/index.html =nofollow noreferrer> http://www.oracle.com/technetwork/java/javafx/samples/index .html

Download Ensemble sample from http://www.oracle.com/technetwork/java/javafx/samples/index.html

动态图表有几个例子,例如高级股票行情图。您可以直接在应用程序中查看其源代码。

There are several examples in it for dynamic charts, e.g. "Advanced Stock Line Chart". You can take a look at their source code directly in the application.

要在轴上显示时间,您可以使用字符串和DateFormatter:

To show time on axis you can use string and DateFormatter:

    BarChart<String, Number> chart = new BarChart<>(new CategoryAxis(), new NumberAxis());

    final XYChart.Series<String, Number> series1 = new XYChart.Series<>();
    chart.getData().addAll(series1);

    SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    Date date = new Date();
    for (int i = 0; i <= 10; i += 1) {
        date.setTime(date.getTime() + i * 11111);
        series1.getData().add(new XYChart.Data(dateFormat.format(date), Math.random() * 500));
    }