-
Notifications
You must be signed in to change notification settings - Fork 95
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
Axes min/max are updated but charts are not updated to the new range #533
Comments
Hey, thanks for the feedback on using our library. Could you provide a minimal sample which reproduces your problem? |
谢谢您的回复,这是我提出问题的原因,你可以运行一下下面的代码会发现X轴更新了但是图没有更新,期待你的回复谢谢! import de.gsi.chart.XYChart;
import de.gsi.chart.axes.spi.DefaultNumericAxis;
import de.gsi.chart.renderer.spi.ErrorDataSetRenderer;
import de.gsi.dataset.spi.DoubleDataSet;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
/**
*
* @author guofan
* @date 2022/7/13
*/
public class ChartFxSample extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
DefaultNumericAxis xAxis = new DefaultNumericAxis();
xAxis.setName("X");
xAxis.setAutoRanging(false);
DefaultNumericAxis yAxis = new DefaultNumericAxis();
yAxis.setName("Y");
XYChart chart = new XYChart(xAxis, yAxis);
DoubleDataSet dataSet = new DoubleDataSet("data");
double[] xValues = new double[1000];
double[] yValues = new double[1000];
for (int i = 0; i < 1000; i++) {
xValues[i] = i;
yValues[i] = Math.sin(i / 10);
}
dataSet.set(xValues, yValues);
ErrorDataSetRenderer renderer = new ErrorDataSetRenderer();
renderer.getDatasets().add(dataSet);
chart.getRenderers().add(renderer);
xAxis.setMin(-500);
xAxis.setMax(1500);
BorderPane borderPane = new BorderPane();
borderPane.setCenter(chart);
Button updateXAxisButton = new Button("updateXAxis");
updateXAxisButton.setOnAction(event -> {
xAxis.setMin(0);
});
borderPane.setBottom(updateXAxisButton);
Scene scene = new Scene(borderPane);
primaryStage.setScene(scene);
primaryStage.setWidth(600);
primaryStage.setHeight(400);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
} |
Ok, I can reproduce the issue, thanks for the fast reply. We usually have fast updating data or use interactive rescaling where the chart lagging one update behind the axes it not really noticeable. Meanwhile as a workaround you can either use a custom axis with the changes you proposed above or use this snippet in your app to force a second redraw:
I'm actually in the process of restructuring the layouting and rendering code for the 11.3 release where i hope to improve problems like this, see #527 and #529 . |
谢谢你的回复,但是没有解决我的问题,我的解决方案是这样的。 import de.gsi.chart.axes.spi.DefaultNumericAxis;
/**
* 可更手动更新的轴
*
* @author guofan
* @date 2022/7/13
*/
public class UpdateNumericAxis extends DefaultNumericAxis {
/**
* 更新轴缓存
*/
public void updateAxisCache() {
updateCachedVariables();
}
} import de.gsi.chart.XYChart;
import de.gsi.chart.axes.spi.DefaultNumericAxis;
import de.gsi.chart.renderer.spi.ErrorDataSetRenderer;
import de.gsi.dataset.spi.DoubleDataSet;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
/**
*
* @author guofan
* @date 2022/7/13
*/
public class ChartFxSample extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
UpdateNumericAxis xAxis = new UpdateNumericAxis();
xAxis.setName("X");
xAxis.setAutoRanging(false);
// 添加更新缓存 Add update cache
xAxis.minProperty().addListener((observable, oldValue, newValue) -> xAxis.updateAxisCache());
DefaultNumericAxis yAxis = new DefaultNumericAxis();
yAxis.setName("Y");
XYChart chart = new XYChart(xAxis, yAxis);
DoubleDataSet dataSet = new DoubleDataSet("data");
double[] xValues = new double[1000];
double[] yValues = new double[1000];
for (int i = 0; i < 1000; i++) {
xValues[i] = i;
yValues[i] = Math.sin(i / 10);
}
dataSet.set(xValues, yValues);
ErrorDataSetRenderer renderer = new ErrorDataSetRenderer();
renderer.getDatasets().add(dataSet);
chart.getRenderers().add(renderer);
xAxis.setMin(-500);
xAxis.setMax(1500);
BorderPane borderPane = new BorderPane();
borderPane.setCenter(chart);
Button updateXAxisButton = new Button("updateXAxis");
updateXAxisButton.setOnAction(event -> {
xAxis.setMin(0);
});
Scene scene = new Scene(borderPane);
borderPane.setBottom(updateXAxisButton);
primaryStage.setScene(scene);
primaryStage.setWidth(600);
primaryStage.setHeight(400);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
} |
@guofan2019 thanks for reporting this issue and sharing your solution. We also noticed this behavior for a long time and assumed it was a mistake in our implementation. We added an extra layout() call after essentially all plot changes to solve the problem, but I think your solution might be more elegant better. We also exclusively use chartfx for fixed charts that don't update in real-time, so this explains why we have also see this problem. I assume many others use this awesome library in this way, so it would be really great if this was fixed in the library. |
I too came across this issue and wanted to add my findings. |
solved by #592, which will be included in the major release coming soon. Sorry for having to live with the workarounds for so long, feel free to reopen if the problems persist on main or in the upcoming 11.3 release. |
Describe the bug
我在用这个开源软件它非常棒,速度非常快但是我遇到一个问题。我在用DefaultNumericAxis类作为横坐标,但是当横坐标更新后我发现图并没有更新,我看到源码中作者是否忘记取更新缓存(调用AbstractAxisParameter 类的updateCachedVariables 方法)希望作者看到以后能修复这个BUG,谢谢祝您天天开心。
I'm using this open source software and it's great, it's really fast but I ran into a problem. I'm using DefaultNumericAxis as the abscissa, but when the abscissa is updated I find that the graph is not updated, I see whether the author forgot to take the update cache in the source code (call the AbstractAxisParameter class updateCachedVariables method). I hope the author can fix this BUG after reading it. Thank you and wish you a happy day.
Environment:
The text was updated successfully, but these errors were encountered: