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
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