JavaFX real-time LineChart with time axis

匿名 (未验证) 提交于 2019-12-03 03:05:02

问题:

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)   

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

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

回答1:

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.

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


回答2:

The class org.jfree.chart.demo.TimeSeriesChartDemo1 is included with the distribution. It is pictured in the demo, and its source illustrates the use of the factory method ChartFactory.createTimeSeriesChart(). There's a related example here.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!