This discussion is archived
5 Replies Latest reply: Jan 19, 2013 4:11 PM by KonradZuse RSS

Bug?  LineChart disappears after trying to rem some of the same data type.

KonradZuse Explorer
Currently Being Moderated
Okay so I created new series to manipulate
XYChart.Series<Double,Double> volts = new XYChart.Series<>();
Now basically this isn't the smartest thing to do, but I needed a walkaround right away. SOmeone I'm making a graph for wanted me to change up the colors, so I set them to how they are laid out in Ensemble, then deleted the ones i didn't need.
     chart.getData().add(ress);   
                           
           chart.getData().add(d);
           chart.getData().add(dummy);
           chart.getData().add(pows);
           
           chart.getData().add(dum);
           chart.getData().add(curs);
          
           chart.getData().add(volts);

           chart.getData().remove(dummy);
           chart.getData().remove(d);
           chart.getData().remove(dum);
       
Now originally I tried to do .removeAll(dummy); but the chart disappeared, then when I tried to remove dummy 2x it would wokr, but the 3rd time it will disappear again... So I basically had to create 3 dummy variables, d, dum, and dummy.....

I also wanted to mention when doing so the spacing in the legend is messed up. More space is in between volts and curs than curs and pows since the dum was in the middle. Weird stuff....

Now I made a topic below asking how to change the color, to which I found .css code, but I figured I didn't want to do too much extra work, which also seems I would need to useFXML with .css, because I don't think you can use css directly can you?

Thanks!
  • 1. Re: Bug?  LineChart disappears after trying to rem some of the same data type.
    KonradZuse Explorer
    Currently Being Moderated
    Bump, anyone have an idea what's up? This will be corrected when I use css, but it's interesting to find this out... I think its a bug.
  • 2. Re: Bug?  LineChart disappears after trying to rem some of the same data type.
    David Grieve Pro
    Currently Being Moderated
    Does this code exhibit the problem? If not, can you modify the code so it does?
        @Override 
        public void start(Stage stage) throws Exception { 
            
            final AnchorPane root = new AnchorPane();
            Scene scene = new Scene(root, 700, 500);
            
            final CategoryAxis xAxis = new CategoryAxis();
            final NumberAxis yAxis = new NumberAxis();
             xAxis.setLabel("Month");
            final LineChart<String,Number> lineChart = 
                    new LineChart<String,Number>(xAxis,yAxis);
            root.getChildren().add(lineChart);
            
            lineChart.setTitle("Stock Monitoring, 2010");      
            
            lineChart.setCreateSymbols(false);     
            lineChart.setAlternativeRowFillVisible(false);
            
            final XYChart.Series series1 = new XYChart.Series();
            series1.setName("Portfolio 1");
            series1.getData().add(new XYChart.Data("Jan", 23));
            series1.getData().add(new XYChart.Data("Feb", 14));
            series1.getData().add(new XYChart.Data("Mar", 15));
            series1.getData().add(new XYChart.Data("Apr", 24));
            series1.getData().add(new XYChart.Data("May", 34));
            series1.getData().add(new XYChart.Data("Jun", 36));
            series1.getData().add(new XYChart.Data("Jul", 22));
            series1.getData().add(new XYChart.Data("Aug", 45));
            series1.getData().add(new XYChart.Data("Sep", 43));
            series1.getData().add(new XYChart.Data("Oct", 17));
            series1.getData().add(new XYChart.Data("Nov", 29));
            series1.getData().add(new XYChart.Data("Dec", 25));
            
            final XYChart.Series series2 = new XYChart.Series();
            series2.setName("Portfolio 2");
            series2.getData().add(new XYChart.Data("Jan", 33));
            series2.getData().add(new XYChart.Data("Feb", 34));
            series2.getData().add(new XYChart.Data("Mar", 25));
            series2.getData().add(new XYChart.Data("Apr", 44));
            series2.getData().add(new XYChart.Data("May", 39));
            series2.getData().add(new XYChart.Data("Jun", 16));
            series2.getData().add(new XYChart.Data("Jul", 55));
            series2.getData().add(new XYChart.Data("Aug", 54));
            series2.getData().add(new XYChart.Data("Sep", 48));
            series2.getData().add(new XYChart.Data("Oct", 27));
            series2.getData().add(new XYChart.Data("Nov", 37));
            series2.getData().add(new XYChart.Data("Dec", 29));
            
            final XYChart.Series series3 = new XYChart.Series();
            series3.setName("Portfolio 3");
            series3.getData().add(new XYChart.Data("Jan", 44));
            series3.getData().add(new XYChart.Data("Feb", 35));
            series3.getData().add(new XYChart.Data("Mar", 36));
            series3.getData().add(new XYChart.Data("Apr", 33));
            series3.getData().add(new XYChart.Data("May", 31));
            series3.getData().add(new XYChart.Data("Jun", 26));
            series3.getData().add(new XYChart.Data("Jul", 22));
            series3.getData().add(new XYChart.Data("Aug", 25));
            series3.getData().add(new XYChart.Data("Sep", 43));
            series3.getData().add(new XYChart.Data("Oct", 44));
            series3.getData().add(new XYChart.Data("Nov", 45));
            series3.getData().add(new XYChart.Data("Dec", 44));
            
            lineChart.getData().addAll(series1, series2, series3);
            stage.setScene(scene); 
            stage.show(); 
    
            // make series2 disappear after the chart is shown.
            Platform.runLater(new Runnable() {
                @Override public void run() {
                    lineChart.getData().removeAll(series2);
                }
            });
        }
  • 3. Re: Bug?  LineChart disappears after trying to rem some of the same data type.
    KonradZuse Explorer
    Currently Being Moderated
    I realized I did not give much code, so let me fix this, and explain again.
    XYChart.Series<Double,Double> dummy = new XYChart.Series<>();
            XYChart.Series<Double,Double> dum = new XYChart.Series<>();
    XYChart.Series<Double,Double> d = new XYChart.Series<>();
    
    
    etc.....
    These are the Series.
     public void initial() {
       
    
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    
                    if(start == false)
                    {
                        
                    root.getChildren().add(chart);
                    
                   
                               
               chart.getData().add(ress);   
                               
               chart.getData().add(d);
               chart.getData().add(dummy);
               chart.getData().add(pows);
               
               chart.getData().add(dum);
               chart.getData().add(curs);
              
               chart.getData().add(volts);
    
               chart.getData().remove(dummy);
               chart.getData().remove(d);
               chart.getData().remove(dum);
               
               
               volts.setName("Voltage");
               ress.setName("Resistance");
               curs.setName("Current");
               pows.setName("Power");
                           fxContainer.setScene(new Scene(root));
                           graph.add(fxContainer);
                           start = true;
                    }
                    else
                    {
                           chart();
                    }
    Basically this is an FX in Swing program and the chart doesn't work if I don't run it on the FX thread (I haven't looked into concurrency too much yet, but I should). The chart method basically adds, deletes, or resets the table, which doesn't really have to do with my issue...

    So you see the original problem was that I added"Dummy" three times. When I tried to remove the 3 "Dummy" positions the chart would not be visible, no error thrown... If I tried to remove 2 it would work, but leave the 1 left in the legend. If I did removeAll() it would do the same thing, not visible and no error....

    I did this because I wasn't sure how to do css without Scenebuilder but it seems like it's easier than I thought, not exactly sure, but I saw that it's Class.setStyle(styles); not sure which class though... But it's interesting I found this little tidbit....
  • 4. Re: Bug?  LineChart disappears after trying to rem some of the same data type.
    KonradZuse Explorer
    Currently Being Moderated
    bump anyone have any idea if this is a bug? Again this isn't how I finalized my work, but I wanted to see if there is a bug found or what.... Should I just report it to JIRA?
  • 5. Re: Bug?  LineChart disappears after trying to rem some of the same data type.
    KonradZuse Explorer
    Currently Being Moderated
    bump anyone have any idea if this is a bug? Again this isn't how I finalized my work, but I wanted to see if there is a bug found or what.... Should I just report it to JIRA?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points