primefaces icon indicating copy to clipboard operation
primefaces copied to clipboard

Chart: LineChart not working when beginning with null-values

Open metaxmx opened this issue 8 years ago • 5 comments

1) Environment

  • PrimeFaces version: 6.2
  • Does it work on the newest released PrimeFaces version? Version? 6.2 is newest release
  • Does it work on the newest sources in GitHub? No
  • Application server + version: Wildfly 10
  • Affected browsers: Firefox, Chrome (latest)
  • Example: See gist: https://gist.github.com/metaxmx/49a966c022f40bcdcfbe51f8596c94af

2) Expected behavior

  • In LineCharts points with the y-axis value "null" are ignored by the graph

3) Actual behavior

  • If the first point in a chart series has a value "null" the graph is not rendered at all (only the canvas).

4) Steps to reproduce

  • Create PrimeFaces Chart of type "line"
  • Create Chart Model with a Chart Series, containing some null-Values in the middle -> no problem, points are ignores
  • Create Chart Model with a Chart Series, starting with a null-Value
  • chart is not rendered

5) Sample XHTML

<p:chart type="line" model="#{chartController.chartModel}"
         id="chartTest"
         style="width:100%; height:210px;">
</p:chart>

<p:chart type="line" model="#{chartController.chartModelWithNull}"
         id="chartTest2"
         style="width:100%; height:210px;">
</p:chart>

6) Sample bean

package com.illucit.controller;

import org.primefaces.model.chart.ChartSeries;
import org.primefaces.model.chart.LineChartModel;

import javax.enterprise.inject.Model;
import java.util.LinkedHashMap;
import java.util.Map;

@Model
public class ChartController {

    private LineChartModel chartModel = new LineChartModel();

    private LineChartModel chartModelWithNull = new LineChartModel();

    public ChartController() {
        chartModel.setTitle("Test Chart");
        ChartSeries series = new ChartSeries();
        Map<Object, Number> data = new LinkedHashMap<Object, Number>();
        data.put(10, 10);
        data.put(20, 30);
        data.put(30, 10);
        data.put(40, null);
        data.put(50, 15);
        series.setData(data);
        chartModel.addSeries(series);

        chartModelWithNull.setTitle("Test Chart, beginning with Null value");
        ChartSeries seriesWithNull = new ChartSeries();
        Map<Object, Number> dataWithNull = new LinkedHashMap<Object, Number>();
        dataWithNull.put(10, null);
        dataWithNull.put(20, 30);
        dataWithNull.put(30, 30);
        dataWithNull.put(40, 40);
        dataWithNull.put(50, 60);
        seriesWithNull.setData(dataWithNull);
        chartModelWithNull.addSeries(seriesWithNull);
    }

    public LineChartModel getChartModel() {
        return this.chartModel;
    }

    public LineChartModel getChartModelWithNull() {
        return chartModelWithNull;
    }
}

7) Analysis

  • null values are encoded as JavaScript String "null", instead of JavaScript value null as in older PrimeFaces versions
  • Apparently jqPlot does not work well, when it encounters a String as a value where it expects a number

metaxmx avatar May 03 '18 10:05 metaxmx

Thanks for the pR!

tandraschko avatar May 05 '18 16:05 tandraschko

Thanks for everybodie's work! I just wanted to make clear, that this worked fine in PF 6.0 and 6.1 and without this fix it is a regression. I am applying the patch it locally in production since 2 weeks. It would be great if it could be applied to 6.2.x branch also...

alfonx avatar May 31 '18 13:05 alfonx

@mertsincan can you merge this into 6.2.6 Elite release?

melloware avatar May 31 '18 14:05 melloware

jquery related regression?

kukel avatar Jun 27 '18 14:06 kukel

jquery related regression?

Yes, 90% sure

alfonx avatar Jun 27 '18 14:06 alfonx