简体   繁体   English

具有时间轴的JavaFX实时LineChart

[英]JavaFX real-time LineChart with time axis

I'm trying to plot real-time graph, with time axis, but I have found the LineChart constructor only has the signature. 我正在尝试使用时间轴绘制实时图形,但我发现LineChart构造函数只有签名。

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

I think embedding jfree chart in javafx is not a proper solution. 我认为在javafx中嵌入jfree图表不是一个合适的解决方案。

I want a few of the jfree features in a javafx LineChart , is this possible? 我想在javafx LineChart使用一些jfree功能,这可能吗?

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

There are several examples in it for dynamic charts, eg "Advanced Stock Line Chart". 动态图表中有几个例子,例如“高级股票线图”。 You can take a look at their source code directly in the application. 您可以直接在应用程序中查看其源代码。

在此输入图像描述

To show time on axis you can use string and DateFormatter: 要在轴上显示时间,可以使用string和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));
    }

The class org.jfree.chart.demo.TimeSeriesChartDemo1 is included with the distribution. org.jfree.chart.demo.TimeSeriesChartDemo1类包含在发行版中。 It is pictured in the demo , and its source illustrates the use of the factory method ChartFactory.createTimeSeriesChart() . 它在演示中描绘,其源代码说明了工厂方法ChartFactory.createTimeSeriesChart() There's a related example here . 有一个相关的例子在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM