knowm / XChart

XChart is a light-weight Java library for plotting data.
http://knowm.org/open-source/xchart
Apache License 2.0
1.5k stars 397 forks source link

Incorrect Y-Axis for Category Chart when using Line Render Style #653

Closed daniel-fontaine closed 2 years ago

daniel-fontaine commented 2 years ago

The y-axis is incorrect for category chart when using line rendering style. The chart becomes correct if the y-axis min is explicitly set to 0 i.e. x chart.getStyler().setYAxisMin(0.0). If the y-axis min is set to something other than 0, the axes are again incorrect. This bug does not occur when using bar rendering style.

Example:

double[] xData = new double[] { 0.0, 1.0, 2.0, 3.0, 4.0 };
double[] yData = new double[] { 2.0, 1.5, 4.0, 3.77, 2.5 };

// Create Chart
CategoryChartBuilder builder = new CategoryChartBuilder();
builder.title("Sample Chart")
    .xAxisTitle("X")
    .yAxisTitle("Y")
    .theme(ChartTheme.Matlab);
CategoryChart chart = builder.build();
chart.getStyler().setDefaultSeriesRenderStyle(CategorySeries.CategorySeriesRenderStyle.Line);
    //    .setYAxisMin(0.0);

chart.addSeries("y(x)", xData, yData);

// Show it
new SwingWrapper(chart).displayChart();
jwedster commented 2 years ago

Identified the same issue today. Thanks Daniel.

timmolter commented 2 years ago

Thanks. I'm looking at it now.

timmolter commented 2 years ago

Fixed. I'll push a release soon.

daniel-fontaine commented 2 years ago

Thanks Tim!

On Sun, Sep 18, 2022 at 2:50 PM Tim Molter @.***> wrote:

Closed #653 https://github.com/knowm/XChart/issues/653 as completed.

— Reply to this email directly, view it on GitHub https://github.com/knowm/XChart/issues/653#event-7409307732, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF6VAPMBYZSWBQLJ5JHJKOLV65P73ANCNFSM5LUL3MBA . You are receiving this because you authored the thread.Message ID: @.***>