JDK-8097482 : LineChart renders noisy lines when the number of data points is large
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8u25
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2015-01-04
  • Updated: 2016-08-23
  • Resolved: 2015-01-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8u60Fixed
Related Reports
Relates :  
Relates :  
Description
When a large number of data points are used to draw a straight line in the chart, the rendered line is not straight.
For example:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;

public class ChartBug extends Application {
    
    @Override
    public void start(Stage primaryStage) {
        //defining the axes
        final NumberAxis xAxis = new NumberAxis();
        final NumberAxis yAxis = new NumberAxis();

        //creating the chart
        final LineChart<Number,Number> lineChart = 
                new LineChart<>(xAxis,yAxis);
        // Disable symbols
        lineChart.setCreateSymbols(false);
        //defining a series
        XYChart.Series series = new XYChart.Series();
        for(int i=0; i<=100; i++)
        {
            series.getData().add(new XYChart.Data<>(i,i));
        }
        lineChart.getData().add(series);
        
        Scene scene  = new Scene(lineChart,800,600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
}

This produces the following chart : http://imgur.com/ddSQT9i,lQ8nNMx#0

While changing 
for(int i=0; i<=100; i++)
        {
            series.getData().add(new XYChart.Data<>(i,i));
        }

To
for(int i=0; i<=10; i++)
        {
            series.getData().add(new XYChart.Data<>(10*i,10*i));
        }

produces a straight line as expected. http://imgur.com/ddSQT9i,lQ8nNMx#1


Comments
Changeset: 45593729d2ab Author: vadim Date: 2015-01-21 09:09 +0300 URL: http://hg.openjdk.java.net/openjfx/8u-dev/rt/rev/45593729d2ab
21-01-2015

Well the suggested workaround actually makes the line worse on my retina MBP (either in retina mode or regular resolution mode). But, the fix does fix it well and makes sense... +1
20-01-2015

+1
20-01-2015

http://cr.openjdk.java.net/~vadim/RT-39758/webrev.00/
20-01-2015

Jonathan, Please review the fix, which is as simple as: diff -r 621745ca1a13 modules/controls/src/main/java/javafx/scene/chart/ValueAxis.java --- a/modules/controls/src/main/java/javafx/scene/chart/ValueAxis.java Mon Jul 28 13:31:28 2014 +0400 +++ b/modules/controls/src/main/java/javafx/scene/chart/ValueAxis.java Tue Jan 20 14:53:08 2015 +0300 @@ -458,7 +458,7 @@ * @return display position */ @Override public double getDisplayPosition(T value) { - return Math.round(offset + ((value.doubleValue() - currentLowerBound.get()) * getScale())); + return offset + ((value.doubleValue() - currentLowerBound.get()) * getScale()); } /** The rounding seems unnecessary, RT-36766, which is related to this, is not affected by this change because the result of getDisplayPosition is still rounded in the Axis.layoutChildren.
20-01-2015

This is likely a chart bug, but might be a rendering bug. Either way, I am leaving it assigned to Vadim for 8u60.
06-01-2015