Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8124333

Can't clear line chart when LineChart.setCreateSymbols(false) is set

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 7u6, 7u13
    • Fix Version/s: 8
    • Component/s: javafx
    • Environment:

      OS = Windows 7
      Java = 1.7.15
      JavaFX = 2.2.5

      Description

      If you create a line chart with option LineChart.setCreateSymbols(false) set to false, then invoking method LineChart.getData().clear() throws a NullPointer exception. This works fine if LineChart.setCreateSymbols(true) is set.

      Suggestion for a work around?

      Here is the stack trace:
      java.lang.NullPointerException
      at javafx.scene.chart.LineChart.seriesRemoved(LineChart.java:377)
      at javafx.scene.chart.XYChart$2.onChanged(XYChart.java:99)
      at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:134)
      at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:48)
      at com.sun.javafx.collections.ObservableListWrapper.callObservers(ObservableListWrapper.java:97)
      at com.sun.javafx.collections.ObservableListWrapper.clear(ObservableListWrapper.java:184)
      at com.sas.analytics.demo.LineChartSample$2.handle(LineChartSample.java:43)
      at com.sas.analytics.demo.LineChartSample$2.handle(LineChartSample.java:1)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:69)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:28)
      at javafx.event.Event.fireEvent(Event.java:171)
      at javafx.scene.Node.fireEvent(Node.java:6863)
      at javafx.scene.control.Button.fire(Button.java:179)
      at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:193)
      at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:336)
      at com.sun.javafx.scene.control.skin.SkinBase$4.handle(SkinBase.java:329)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:64)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:217)
      at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:170)
      at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
      at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:53)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
      at javafx.event.Event.fireEvent(Event.java:171)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3328)
      at javafx.scene.Scene$MouseHandler.process(Scene.java:3168)
      at javafx.scene.Scene$MouseHandler.access$1900(Scene.java:3123)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1563)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2265)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:250)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:173)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:292)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:528)
      at com.sun.glass.ui.View.notifyMouse(View.java:922)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
      at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
      at java.lang.Thread.run(Thread.java:722)

      Here is a program that uses the line chart sample from the JavaFX tutorial page that replicates this problem:
      public class LineChartSample extends Application
      {
      private static String[] MONTHS = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

      private LineChart<String,Number> lineChart;

          @Override public void start(Stage stage)
          {
              // Create series button
              Button createButton = new Button("Add Series");
              createButton.setOnAction(new EventHandler<ActionEvent>()
              {
      @Override
      public void handle(ActionEvent arg0)
      {
      addSeries();
      }
              });

              // Remove all series button
              Button removeAllButton = new Button("Remove All");
              removeAllButton.setOnAction(new EventHandler<ActionEvent>()
              {
      @Override
      public void handle(ActionEvent arg0)
      {
      lineChart.getData().clear();
      }
              });
              
              // Button box
              HBox buttonBox = new HBox(4);
              buttonBox.getChildren().addAll(createButton, removeAllButton);

              // Line chart
              final CategoryAxis xAxis = new CategoryAxis();
              final NumberAxis yAxis = new NumberAxis();
              xAxis.setLabel("Month");
              lineChart = new LineChart<String,Number>(xAxis,yAxis);
              lineChart.setTitle("Stock Monitoring, 2010");
              lineChart.setCreateSymbols(false);
              addSeries();
              
              // Content box
              VBox contentBox = new VBox();
              VBox.setVgrow(contentBox, Priority.ALWAYS);
              contentBox.getChildren().addAll(buttonBox, lineChart);
           
              stage.setTitle("Line Chart Sample");
              Scene scene = new Scene(contentBox, 800, 600);
              stage.setScene(scene);
              stage.show();
          }
          
          private void addSeries()
          {
              XYChart.Series series = new XYChart.Series();
              series.setName("Series " + (lineChart.getData().size() + 1));
              
              for (String month : MONTHS)
              {
               series.getData().add(new XYChart.Data(month, Math.random() * 100));
              }
              
              lineChart.getData().add(series);
          }
              
          public static void main(String[] args)
          {
              launch(args);
          }

      }

      Thanks.
      Stefan

        Attachments

          Activity

            People

            • Assignee:
              psomashe Parvathi Somashekar (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved:
                Imported: