Why can't I can't modify a Chart from the .fxml in my Controller?












-2















I defined a BarChart in my .fxml file that i inject into my controller using the @FXML annotation. But when I insert a data series, the chart still shows up as empty in my application, even though debugger output confirms that I successfully insert the data series into my chart. Do I need to tell the chart's view to update somehow?



I could surely just work around the problem by getting a pane from the fxml into which I would then insert the chart (that does work, and I used this workaround in the past). But I'm curious about what I'm doing wrong.



Thanks for your help!



Controller code:



@FXML private BarChart<Number,String> barChart;

//...

barChart.getData().add( new XYChart.Series<Number,String>("blabla",

eventService
.getTopTen(EventType.MUSICAL)
.entrySet()
.stream()
.map(entry -> new XYChart.Data<>((Number)entry.getValue(),entry.getKey().getName(),entry))
.collect(Collectors.collectingAndThen(toList(), FXCollections::observableArrayList))
));


My FXML:



//...

<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="at.ac.tuwien.inso.sepm.ticketline.client.gui.event.EventTopTenController">
<children>
<Button layoutX="267.0" layoutY="361.0" mnemonicParsing="false" onAction="#MusicalTopTenButtonHandler" text="Literature" />
<BarChart fx:id="barChart" layoutX="52.0" layoutY="14.0" prefHeight="338.0" prefWidth="510.0">
<xAxis>
<NumberAxis side="BOTTOM" />
</xAxis>
<yAxis>
<CategoryAxis side="LEFT" />
</yAxis>
</BarChart>
</children>











share|improve this question























  • Please edit your question to provide a Minimal, Complete, and Verifiable example demonstrating the problem.

    – Slaw
    Jan 2 at 3:52


















-2















I defined a BarChart in my .fxml file that i inject into my controller using the @FXML annotation. But when I insert a data series, the chart still shows up as empty in my application, even though debugger output confirms that I successfully insert the data series into my chart. Do I need to tell the chart's view to update somehow?



I could surely just work around the problem by getting a pane from the fxml into which I would then insert the chart (that does work, and I used this workaround in the past). But I'm curious about what I'm doing wrong.



Thanks for your help!



Controller code:



@FXML private BarChart<Number,String> barChart;

//...

barChart.getData().add( new XYChart.Series<Number,String>("blabla",

eventService
.getTopTen(EventType.MUSICAL)
.entrySet()
.stream()
.map(entry -> new XYChart.Data<>((Number)entry.getValue(),entry.getKey().getName(),entry))
.collect(Collectors.collectingAndThen(toList(), FXCollections::observableArrayList))
));


My FXML:



//...

<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="at.ac.tuwien.inso.sepm.ticketline.client.gui.event.EventTopTenController">
<children>
<Button layoutX="267.0" layoutY="361.0" mnemonicParsing="false" onAction="#MusicalTopTenButtonHandler" text="Literature" />
<BarChart fx:id="barChart" layoutX="52.0" layoutY="14.0" prefHeight="338.0" prefWidth="510.0">
<xAxis>
<NumberAxis side="BOTTOM" />
</xAxis>
<yAxis>
<CategoryAxis side="LEFT" />
</yAxis>
</BarChart>
</children>











share|improve this question























  • Please edit your question to provide a Minimal, Complete, and Verifiable example demonstrating the problem.

    – Slaw
    Jan 2 at 3:52
















-2












-2








-2








I defined a BarChart in my .fxml file that i inject into my controller using the @FXML annotation. But when I insert a data series, the chart still shows up as empty in my application, even though debugger output confirms that I successfully insert the data series into my chart. Do I need to tell the chart's view to update somehow?



I could surely just work around the problem by getting a pane from the fxml into which I would then insert the chart (that does work, and I used this workaround in the past). But I'm curious about what I'm doing wrong.



Thanks for your help!



Controller code:



@FXML private BarChart<Number,String> barChart;

//...

barChart.getData().add( new XYChart.Series<Number,String>("blabla",

eventService
.getTopTen(EventType.MUSICAL)
.entrySet()
.stream()
.map(entry -> new XYChart.Data<>((Number)entry.getValue(),entry.getKey().getName(),entry))
.collect(Collectors.collectingAndThen(toList(), FXCollections::observableArrayList))
));


My FXML:



//...

<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="at.ac.tuwien.inso.sepm.ticketline.client.gui.event.EventTopTenController">
<children>
<Button layoutX="267.0" layoutY="361.0" mnemonicParsing="false" onAction="#MusicalTopTenButtonHandler" text="Literature" />
<BarChart fx:id="barChart" layoutX="52.0" layoutY="14.0" prefHeight="338.0" prefWidth="510.0">
<xAxis>
<NumberAxis side="BOTTOM" />
</xAxis>
<yAxis>
<CategoryAxis side="LEFT" />
</yAxis>
</BarChart>
</children>











share|improve this question














I defined a BarChart in my .fxml file that i inject into my controller using the @FXML annotation. But when I insert a data series, the chart still shows up as empty in my application, even though debugger output confirms that I successfully insert the data series into my chart. Do I need to tell the chart's view to update somehow?



I could surely just work around the problem by getting a pane from the fxml into which I would then insert the chart (that does work, and I used this workaround in the past). But I'm curious about what I'm doing wrong.



Thanks for your help!



Controller code:



@FXML private BarChart<Number,String> barChart;

//...

barChart.getData().add( new XYChart.Series<Number,String>("blabla",

eventService
.getTopTen(EventType.MUSICAL)
.entrySet()
.stream()
.map(entry -> new XYChart.Data<>((Number)entry.getValue(),entry.getKey().getName(),entry))
.collect(Collectors.collectingAndThen(toList(), FXCollections::observableArrayList))
));


My FXML:



//...

<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="at.ac.tuwien.inso.sepm.ticketline.client.gui.event.EventTopTenController">
<children>
<Button layoutX="267.0" layoutY="361.0" mnemonicParsing="false" onAction="#MusicalTopTenButtonHandler" text="Literature" />
<BarChart fx:id="barChart" layoutX="52.0" layoutY="14.0" prefHeight="338.0" prefWidth="510.0">
<xAxis>
<NumberAxis side="BOTTOM" />
</xAxis>
<yAxis>
<CategoryAxis side="LEFT" />
</yAxis>
</BarChart>
</children>








java javafx






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 3:34









Florian WicherFlorian Wicher

184




184













  • Please edit your question to provide a Minimal, Complete, and Verifiable example demonstrating the problem.

    – Slaw
    Jan 2 at 3:52





















  • Please edit your question to provide a Minimal, Complete, and Verifiable example demonstrating the problem.

    – Slaw
    Jan 2 at 3:52



















Please edit your question to provide a Minimal, Complete, and Verifiable example demonstrating the problem.

– Slaw
Jan 2 at 3:52







Please edit your question to provide a Minimal, Complete, and Verifiable example demonstrating the problem.

– Slaw
Jan 2 at 3:52














2 Answers
2






active

oldest

votes


















0














You can use highcharts library instead of this. It support json format which can simplify your problem.






share|improve this answer































    0














    I figured it out already. I had the fxml loaded into my program twice, by mistake. After calling the method in the controller, one of those Nodes was updated, the other one wasn't. I was just looking at the one that wasn't. Thanks anyways!






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000925%2fwhy-cant-i-cant-modify-a-chart-from-the-fxml-in-my-controller%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      You can use highcharts library instead of this. It support json format which can simplify your problem.






      share|improve this answer




























        0














        You can use highcharts library instead of this. It support json format which can simplify your problem.






        share|improve this answer


























          0












          0








          0







          You can use highcharts library instead of this. It support json format which can simplify your problem.






          share|improve this answer













          You can use highcharts library instead of this. It support json format which can simplify your problem.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 3:38









          Yash SharmaYash Sharma

          112




          112

























              0














              I figured it out already. I had the fxml loaded into my program twice, by mistake. After calling the method in the controller, one of those Nodes was updated, the other one wasn't. I was just looking at the one that wasn't. Thanks anyways!






              share|improve this answer




























                0














                I figured it out already. I had the fxml loaded into my program twice, by mistake. After calling the method in the controller, one of those Nodes was updated, the other one wasn't. I was just looking at the one that wasn't. Thanks anyways!






                share|improve this answer


























                  0












                  0








                  0







                  I figured it out already. I had the fxml loaded into my program twice, by mistake. After calling the method in the controller, one of those Nodes was updated, the other one wasn't. I was just looking at the one that wasn't. Thanks anyways!






                  share|improve this answer













                  I figured it out already. I had the fxml loaded into my program twice, by mistake. After calling the method in the controller, one of those Nodes was updated, the other one wasn't. I was just looking at the one that wasn't. Thanks anyways!







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 2 at 3:54









                  Florian WicherFlorian Wicher

                  184




                  184






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000925%2fwhy-cant-i-cant-modify-a-chart-from-the-fxml-in-my-controller%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas