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

Java Chart Legend Update loops unnecessarily and causes performance issues

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      I've a linechart which shows regions on Y axis and cars in X axis. When around 200 elements application really starts to lag.

      So I've searched for the reason and I've found in LineChart:

      @Override protected void updateLegend(){
      legend.getItems().clear();
      if(getData() != null) {
      for(int seriesIndex = 0; seriesIndex < getData().size(); seriesIndex++){
      Series<X,Y> series = getData().get(seriesIndex);
      LegendItem legenditem = new LegendItem(series.getName());
      legendItem.getSymbol().getStyleClass().addAll("chart-line-symbol", "series"+seriesIndex, series.defaultColorStyleClass);
      legend.getItems().add(legenditem);
      }
      }
      if(legend.getItems().size > 0){
      if(getLegend()==null) {
      setLegend(legend);
      }
      }
      else{
      setLegend(null);
      }
      }

      So the problem here is update method clears everything and loops through every item. So if I've 350 items it loops through all of them and when 351st item is added, it loops through 351 times again. Instead of that i deleted the clear line and for loop and instead of defining Series<X,Y> series I've changed this line:

      LegendItem legenditem = new LegendItem(getData().get(getData().size()-1).getName());

      And works like a charm. I strongly believe the current situation in linechart legend update is mistake. For my 350 records it took around a minute for chart to actually draw legends but now it takes a second.



      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              aghaisas Ajit Ghaisas
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: