有效地更新JavaFX图表上方的线/标记 [英] Efficiently updating lines/markers on top of a JavaFX chart

查看:65
本文介绍了有效地更新JavaFX图表上方的线/标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了JavaFX LineChart,它需要近一秒钟的时间呈现,并且我想在此图表上移动一个垂直标记(光标位置),该图表非常频繁地更新.

I use a JavaFX LineChart which takes nearly a second to be rendered and I want to move a vertical marker (cursor position) over this chart which is updated very frequently.

我测试了以下解决方案:

I tested the following solutions:

但是,这些解决方案不适用于大图表上的频繁标记更新.每当标记发生变化时,整个图表都会重新绘制.

However, these solutions are not made for frequent marker updates on big charts. Whenever a marker changes the whole chart is redrawn.

当标记更新时,如何防止Java重绘整个图表? 我想到了可以在图表周围放置并缓存图表图像的包装器组件,只要图表内容和图表边界不变即可.是否存在类似的东西,或者该如何实现?

How can I prevent Java from redrawing the whole chart when the marker gets updated? I thought of a wrapper component that can be put around the chart and caches the chart image as long as the chart content and chart boundaries do not change. Does something like that exist or how could one implement this?

推荐答案

原来,该解决方案比我想象的要容易得多. 每个JavaFX组件(Node)都有一个cache属性,可以将其设置为true,以便将渲染的节点缓存为位图.这正是我想要的.

It turned out that the solution is much easier than I thought. Each JavaFX component (Node) has a cache property which can be set to true in order to cache the rendered node as bitmap. This was exactly what I was looking for.

因此,一种有效的解决方案是将图表和所有标记线放入StackPane,并为图表启用缓存.其余内容已在在JavaFX图表中添加线如何添加值标记到JavaFX图表?(如何创建StackPane以及如何计算和更新标记线).

An efficient solution is therefore to put the chart and all marker lines into a StackPane and enable caching for the chart. The rest is already explained in Adding a line in a JavaFX chart and How to add a value marker to JavaFX chart? (how to create the StackPane and how to calculate and update the marker lines).

这篇关于有效地更新JavaFX图表上方的线/标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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