Skip to content

NaNs aren't handled correctly on the Y axis #243

@33d

Description

@33d

I've been using NaNs in series to represent where I don't have data on the X axis, but if the series starts with NaN, an extra point appears at the start.

This sample should show one point at (2.0, 1.0), but an extra point appears at (1.0, 1.0):

import org.knowm.xchart.QuickChart;
import org.knowm.xchart.SwingWrapper;
import org.knowm.xchart.XYChart;
import org.knowm.xchart.style.markers.Circle;

public class Bug {

	public static void main(String[] args) throws Exception {

		double[] xData = new double[] { 1.0, 2.0 };
		double[] yData = new double[] { Double.NaN, 1.0 };

		// Create Chart
		XYChart chart = QuickChart.getChart("Sample Chart", "X", "Y", "1", xData, yData);

		chart.getSeriesMap().get("1").setMarker(new Circle());

		// Show it
		new SwingWrapper(chart).displayChart();

	}
}

Changing PlotContent_XY:107 from if (next == NaN) to if (Double.isNaN(next)) seems to fix the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions