我正在开发一个应用程序,它解析一个文本文件,并在某些发送操作之间查找时间,简而言之,这是一个简单的视觉辅助。
我的问题是,StackedBarCharts x轴上的排序已经出错,如下面链接的图像所示;
生成这些图表的相关代码;
public boolean updateBarChart(Tab t, DataHolder dock) {
Node n = t.getContent();
Node graph = n.lookup("#Graph");
StackedBarChart bc = (StackedBarChart) graph;
//Barchart
NumberAxis xAxis = new NumberAxis();
NumberAxis yAxis = new NumberAxis();
bc.setTitle("Summary");
bc.getData().clear();
bc.setLegendVisible(true);
bc.setCategoryGap(1);
xAxis.setTickLabelRotation(90);
ArrayList<String> tempArr = dock.getUniqueActionNumbers();
for(String s : tempArr)
{
bc.getData().add(dock.calculateIntervalsBetweenActions(s));
}
bc.getXAxis().setAutoRanging(true);
bc.getYAxis().setAutoRanging(true);
return true;
}生成该系列的代码,其中:
ConstantStrings是一个不断重新锁定字符串的ENUM,
PairValue是为一个简单的本地缓存系统而制作的简单的家庭酿造的一对,所以每次我想要一个特定值的每个实例时,我都不需要搜索整个数据结构。
public XYChart.Series<String, Number> calculateIntervalsBetweenActions(String actionNumber)
{
XYChart.Series returnValue = new XYChart.Series();
returnValue.setName(actionNumber);
LocalTime lastTime = null;
TreeMap<Integer, Integer> listOfNumbers = new TreeMap<Integer, Integer>();
int maxVal = 0;
ArrayList<PairValue> temp = metaMap.get(ConstantStrings.RECIEVED_ACTION_NUMBER);
if (temp != null)
{
for( PairValue p : temp)
{
String s = dp.get(p.getNodePlace()).getTokens().get(p.getPointPlace()).getValue();
if (!s.equals(actionNumber))
continue;
if(lastTime != null)
{
LocalTime tempTime = LocalTime.parse(dp.get(p.getNodePlace()).getTimestamp());
int seconds = (int) lastTime.until(tempTime, SECONDS);
if(seconds > maxVal) maxVal = seconds;
Integer count = listOfNumbers.get(seconds);
listOfNumbers.put(seconds, (count == null) ? 1 : count + 1);
lastTime = tempTime;
}
else lastTime = LocalTime.parse(dp.get(p.getNodePlace()).getTimestamp());
}
//todo add filter so the user can choose what to ignore and not.
for(int i = 2; i <= maxVal; i++) {
Integer find = listOfNumbers.get(i);
if(find != null) {
XYChart.Data toAdd = new XYChart.Data(Integer.valueOf(i).toString(), find);
returnValue.getData().add(toAdd);
}
}
}
else Logger.getGlobal().warning("Could not find meta map for Recieved action numer, aborting");
return returnValue;
}我的怀疑在于序列添加的顺序,但在我看来,这不重要,所以我的问题是:有什么简单的方法来正确地排序这些值吗?
发布于 2017-06-07 21:03:05
在我的头撞在墙上的不理解之后,找到了解决办法:
这是我用来删除0-值的代码片段,为您自己的目的而修改。
ObservableList<XYChart.Series> xys = bc.getData();
for(XYChart.Series<String,Number> series : xys) {
ArrayList<XYChart.Data> removelist = new ArrayList<>();
for(XYChart.Data<String,Number> data: series.getData()) {
if(data.getYValue().equals(0)) removelist.add(data);
}
series.getData().removeAll(removelist);
}https://stackoverflow.com/questions/44419356
复制相似问题