-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redrawing chart after updating Datasets doesn't work consistently #259
Comments
Hi Aleksandr, until the real experts show up, |
First, thanks for your interest in chart-fx @asmirn1! In addition to what @milo-gsi already mentioned, you may also want to replace the The latter is -- especially for large data sets or fast updates -- more memory efficient and faster, also because many listeners are attached to the data sets directly. The N.B. If modifying in-place, its always good to first grab the The setter in the 'DoubleDataSet` -- which you could also use equally in your case -- illustrates this a bit more in detail: The critical part is: dataSet.lock().writeLockGuard(() -> {
// [..] modify the data set w/o triggering events
});
fireInvalidated(new UpdatedDataEvent(dataSet)); // trigger update-event explicitly We should add (better write) this to the documentation... ;-) Let us know if this helps with your issue. |
@milo-gsi you are a bit too modest... ;-) You write very nice data acquisition applications used in production with ten thousands of data points that are updating at 25 Hz... maybe we should show-case a bit more what you and others are doing with this little lib. |
Thank you for your quick replies! I've tried your suggestions and what worked for me is the following
Calling @RalphSteinhagen Thank you for your suggestions about modifying in-place and using I really like ChartFX. It's definitely the best option for plotting charts in JavaFX, that I tried so far. However, when I have any issues with ChartFX, I find myself going through a lengthy process of trial and error. Is there any other documentation for ChartFX other than the code examples on Github? |
@asmirn1 unfortunately not (yet). This is a long-standing effort/request (see e.g. #255) which we'd like to follow-up but couldn't find the time yet because of other (internally/unrelated) reasons. Any help on that front (ie. good beginners -> advanced users tutorial) would be highly appreciated. Please feel cordially invited to contribute to that effort! 😁 |
@asmirn1 regardless you may want to modify your code to (wrong line ordering, duplicate clear/add, missing event mapped to 'null'). public void update(List<DataPoint> dataPoints) {
DoubleDataSet dataSet = new DoubleDataSet("DataSet");
for (DataPoint dataPoint : dataPoints) {
double retTime = dataPoint.getRetTime();
double intensity = dataPoint.getIntensity();
dataSet.add(retTime, intensity);
}
renderer.getDatasets().setAll(dataSet);
// dataSet.fireInvalidated(new UpdatedDataEvent(dataSet)); // should be OPTIONAL/not needed
// chart.layout(); // should not be needed (not recommended)
} If you could let me know if this workd for you!? 😄 |
@RalphSteinhagen The actual code looks more like this:
As you see, I've tried to modify the code to use |
@asmirn1 would you perhaps have a MVP example that for this? Can you reproduce this with one of the samples in the master branch and/or 11.2.0 tagged version? Your Java version? OS? Any additional info would be helpful to track this down. |
@RalphSteinhagen Here is a short video of the issue: I haven't tried different version of ChartFX. I'll let you know the results when I try though. |
@asmirn1 thanks.:+1: I'm having a look at it. |
N.B. optional animation of currentLowerBound caused caching issues -> removed animation functionality, recompute scale whenever the min, max, or axisLength changes, and moved caching of offset (default getDisplayPosition(..) impl) to AbstractAxisParameter.AbstractAxisParameter Since most user care for performance rather than animation, the animation feature should be moved to another generic Axis implementation that wraps the original axis and that translates the actual min/max to a time-filtered min/max that is forwarded to the delegate Axis.
@asmirn1 this was a proper bug related to caching of the scale parameter in Your usage didn't have anything directly to do with the bug. However, your MVP and the way you tested -- walking through the list using keyboard events -- nicely emphasized and helped to localize the bug. N.B. We usually tend to do mouse-based test or automatically via the TestFX robot (which acts similar) and didn't catch this because the mouse typically generates more than one event and the bug occurred only for the first update event. Thanks again for the MVP. In the end, this helped a lot! Will do a PR for the fixed branch soon. Meanwhile, if you could confirm that also fixes the issue/symptoms in your application. Thanks in advance and much appreciated. |
N.B. optional animation of currentLowerBound caused caching issues -> removed animation functionality, recompute scale whenever the min, max, or axisLength changes, and moved caching of offset (default getDisplayPosition(..) impl) to AbstractAxisParameter.AbstractAxisParameter Since most user care for performance rather than animation, the animation feature should be moved to another generic Axis implementation that wraps the original axis and that translates the actual min/max to a time-filtered min/max that is forwarded to the delegate Axis. N.B. suppresses false 'cache==null' -- called from static initializer
@RalphSteinhagen I'm glad that it was helpful. Thank you for your quick responses and fixes. To test the new code, should I compile the master branch or the version 11.2.0 already contains this bug fix? |
@asmirn1 for the time being you'd need to test against the 'fixIssue259' branch. |
If you do not want to compile yourself, you can also use the snapshot repository as described here. Just enable the snapshot repository and use |
N.B. optional animation of currentLowerBound caused caching issues -> removed animation functionality, recompute scale whenever the min, max, or axisLength changes, and moved caching of offset (default getDisplayPosition(..) impl) to AbstractAxisParameter.AbstractAxisParameter Since most user care for performance rather than animation, the animation feature should be moved to another generic Axis implementation that wraps the original axis and that translates the actual min/max to a time-filtered min/max that is forwarded to the delegate Axis. N.B. suppresses false 'cache==null' -- called from static initializer
Hi all, I just want to confirm that with the version fixIssue259, everything works as expected. Thank you! |
Hi! Thank you for your work on ChartFX.
I'm having an issue with redrawing a chart after updating its datasets. I update datasets as follows:
where
renderer
isErrorDataSetRenderer
added to anXYChart
.When I call this function, sometimes I get a correct plot and sometimes I get a blank background. Here are a few examples:
I was able to solve this issue by calling
chart.layout()
after I update datasets, as follows:The latter code works and displays all plots correctly whenever the legend is visible (i.e. chart.setLegendVisible(true)). However, when the legend isn't visible, then the plots are still sometimes displayed and sometimes not. I want my users to be able to hide the legend, so I guess I need another solution for my problem.
Maybe, I just don't call a correct function to update charts. What is the recommended ways to redraw plots after updating datasets?
The text was updated successfully, but these errors were encountered: