I've a moving line chart (live chart where the data moves each second ie, the lower bound and the upper bound as well as the series that displays the line are updated each second). Once every minute, I also display a text object anchored to a particular xy value on the chart.
Each second the entire chart gets updated and so does this text object (the text object moves each second)
Issue:
The text object is not moving past the lower bound
I'm creating the text object and then adding it to a XYChart.Data point using the setNode() API, then setting this data point to a XYChart.Series and setting the style on it.
I'm not able to figure out a way to dispose this text object.
Code: Creating Text Object and setting it to the XYChart.Data object
Text moaLabel = new Text("MHRext\nUS1\nUnknown");
Data<Date, Integer> moaPlot = new Data<>();
moaPlot.setNode(moaLabel);
moaPlot.setXValue(xPosition);
moaPlot.setYValue(yPosition);
Adding the Data object to the series object
textSeries.getData().add(moaPlot);
CSS
.chart-series-line-text-mode {
-fx-stroke-width: 0px;
-fx-stroke: #FFFFFF;
-fx-effect: null;
}
I found a solution to my problem.
The approach is to check if the moaPlot.getXValue().equals(lowerBound)
then remove it from the textSeries
list.
In my case since the chart moves every second, I've the following code in an scheduler that runs every second.
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(()->{
textSeries.getData().removeIf(moa -> (moa.getXValue().before(lowerBound)));
}, 0, 1, TimeUnit.SECONDS);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.