Skip to content
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

ChartCanvas Positioning #3

Closed
Peetzn opened this issue Nov 21, 2017 · 7 comments
Closed

ChartCanvas Positioning #3

Peetzn opened this issue Nov 21, 2017 · 7 comments

Comments

@Peetzn
Copy link

Peetzn commented Nov 21, 2017

The layout X and Y of the ChartCanvas are set to the X and Y values of the ChartViewer in its layoutChildren method. The works well only if the ChartViewer is placed at the point of origin (x=0 and y=0) in its surrounding container. Otherwise the ChartCanvas will be placed outside of the ChartViewer.
The layout x and y position the node inside its parent. Therefore the ChartCanvas is placed inside the Chartviewer exactly as the ChartViewer is placed in its parent node which means that the Canvas will be plaxed at X2 and Y2 in the parent node.

See javadoc of Node:

Each Node also has a read-only boundsInParent variable which specifies the bounding rectangle of the Node after all transformations have been applied, including those set in transforms, scaleX/scaleY, rotate, translateX/translateY, and layoutX/layoutY. It is called "boundsInParent" because the rectangle will be relative to the parent's coordinate system. This is the 'visual' bounds of the node. <

Example for reproduction:
Placing multiple Charts in a VBox (or HBox) will illustrate the problem pretty well, for the coordinates add up for each chart and the gaps are getting bigger.

@jfree
Copy link
Owner

jfree commented Nov 21, 2017

Thanks for the report. I believe the correct fix is to set the x and y to 0, right? I've committed this change.

@zugaldia
Copy link

@jfree Thanks for the quick fix, I believe I'm hitting this issue. Where can I find 1.0.1-SNAPSHOT referenced in ec1fd3b? It doesn't seem to be available on Sonatype.

@jfree
Copy link
Owner

jfree commented Dec 30, 2017

SNAPSHOTs aren't being uploaded anywhere yet, but I just uploaded version 1.0.1 so you can use that.

@zugaldia
Copy link

@jfree Looks like the fix did the trick, thank you for pushing 1.0.1!

@ebaisch
Copy link

ebaisch commented Jan 13, 2018

@jfree I am actually having the same issue with the latest build. I am trying to have it display in a GridPane and it will not display unless it is the actual scene. I have 3 cases, 2 of them don't work and one does work but the example that works can't be put inside another hbox or vbox or else it stops working.

//This Doesn't work
ChartViewer chartViewer = new ChartViewer(chart);
  GridPane.setConstraints(chartViewer, 0, 1);
  gridPane.getChildren().add(chartViewer);
  Scene primaryScene = new Scene(gridPane);

// This also doesn't work
VBox vbox = new VBox();
        HBox parent = new HBox();
        Node container = useWorkaround(chartViewer);
        HBox.setHgrow(container, Priority.ALWAYS);
        parent.getChildren().add(container);
        vbox.getChildren().add(parent);
        Scene primaryScene = new Scene(vbox);

// This works
       HBox parent = new HBox();
        Node container = useWorkaround(chartViewer);
        HBox.setHgrow(container, Priority.ALWAYS);
        parent.getChildren().add(container);
        Scene primaryScene = new Scene(parent);

// Method found in #6 used to test
private Node useWorkaround(ChartViewer viewer) {
        if (true) {
            return new StackPane(viewer);
        }
        return viewer;
    }

@romdhani1987
Copy link

@ebaisch hi did you resolve this Problem ? because i want to draw a chart i use JFreeChart-FX 1.0.1
but i don't have any error but i can see nothing i think i have the same problem like you.
Thank you .

@fimbriano
Copy link

@ebaisch @jfree Hi, I'm still having this issue while trying to use a gridpane. Is there a workaround or do you have any suggestions on what to use instead of a gridpane?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants