JavaFX实时LineChart与时间轴 [英] JavaFX real-time LineChart with time axis

查看:3663
本文介绍了JavaFX实时LineChart与时间轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用时间轴绘制实时图,但我发现 LineChart 构造函数只有签名。

I'm trying to plot real-time graph, with time axis, but I have found the LineChart constructor only has the signature.

LineChart(Axis<X> xAxis, Axis<Y> yAxis)  

我想在javafx中嵌入jfree图表不是一个合适的解决方案。

I think embedding jfree chart in javafx is not a proper solution.

我想要一个javafx中的一些jfree特性 LineChart ,这是否可能?

I want a few of the jfree features in a javafx LineChart, is this possible?

推荐答案

=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));
    }

这篇关于JavaFX实时LineChart与时间轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆