JavaFX LineChart:在图表中间插入新数据 [英] JavaFX LineChart: Insert new data in the middle of the chart

查看:1563
本文介绍了JavaFX LineChart:在图表中间插入新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有JavaFX的折线图:

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

XYChart.Series series = new XYChart.Series();

lineChart.getData()。add(series);

我想连续添加数据到序列,因此值到达的顺序不能预料到的。例如,索引可以在0和系列的当前大小之间。

  series.getData()。add XYChart.Data(index,value));考虑下面的情况:



<$ p $ <$ p <$ p

  // initializing ... 
series.getData()。add(new XYChart.Data(1,400));
series.getData()。add(new XYChart.Data(3,500));
series.getData()。add(new XYChart.Data(8,100));
series.getData()。add(new XYChart.Data(12,120));
series.getData()。add(new XYChart.Data(20,300));

//以后...
series.getData()。add(new XYChart.Data(2,450));
series.getData()。add(new XYChart.Data(5,300));
series.getData()。add(new XYChart.Data(15,200));

问题是如何描绘图形。在上面的例子中,在索引20处,图形循环回到索引2.它看起来像这样:



但我想它看起来像这样:



需要什么设置才能正确更新图形,

解决方案

对于JavaFX 9,这个问题有一个新的答案。



有JDK9,请尝试

  lineChart.setAxisSortingPolicy(LineChart.SortingPolicy.X_AXIS); 

(这是JavaFX 9的默认设置)



如果您想要按照添加的顺序绘制数据,请使用:

  lineChart.setAxisSortingPolicy SortingPolicy.NONE); 

查看信息:
http://download.java.net/jdk9/jfxdocs/javafx/scene/chart/LineChart.html#axisSortingPolicyProperty


I'm using a line chart with JavaFX:

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

XYChart.Series series = new XYChart.Series();

lineChart.getData().add(series);

I want to add data to the series successively, thereby the order in which the values arrive can not be predicted. For example, the index can be between 0 and the current size of the series.

series.getData().add(new XYChart.Data(index, value));

Consider the following scenario:

//initializing...
series.getData().add(new XYChart.Data(1, 400));
series.getData().add(new XYChart.Data(3, 500));
series.getData().add(new XYChart.Data(8, 100));
series.getData().add(new XYChart.Data(12, 120));
series.getData().add(new XYChart.Data(20, 300));

//later...
series.getData().add(new XYChart.Data(2, 450));
series.getData().add(new XYChart.Data(5, 300));
series.getData().add(new XYChart.Data(15, 200));

The problem is how the graph is depicted. In the example above, at index 20 the graph makes a loop back to index 2. It looks like this:

But I want it to look like this:

What settings are necessary to update the graph properly without additional lines crossing the graph?

解决方案

There is a new answer to this problem with JavaFX 9.

If you have JDK9, try

lineChart.setAxisSortingPolicy(LineChart.SortingPolicy.X_AXIS);

(this is the default setting for JavaFX 9)

If you want for data to be plotted in the order it was added use:

lineChart.setAxisSortingPolicy(LineChart.SortingPolicy.NONE);

See information here: http://download.java.net/jdk9/jfxdocs/javafx/scene/chart/LineChart.html#axisSortingPolicyProperty

这篇关于JavaFX LineChart:在图表中间插入新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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