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
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
- relates to
-
JDK-8134315 [LineChart] Blurry elements since 8u60
- Open
-
JDK-8163486 NumberAxis: inaccurate rendering of ticks when tick unit is low
- Resolved