Stacked area chart does not render sometimes

UI Components for JSF
Post Reply
dparasam
Posts: 9
Joined: 17 Nov 2016, 00:20

08 Dec 2017, 17:15

When the LineChartModel has setStacked set to true, certain data series causes the chart to not render. The error I see in the browser console then is:

Code: Select all

TypeError: this._plotData[aq][ap] is undefined    (charts.js.xhtml:1:36597)
Here is the code to build the chart model that runs into this problem:

Code: Select all

    final int SECOND = 1000; // milliseconds
    final int MINUTE = 60 * SECOND;

    public void updateChart() {
        _model = new LineChartModel();
        _model.setStacked(true);

        LineChartSeries newSeries1 = generateSeries("series1", MINUTE);
        LineChartSeries newSeries2 = generateSeries("series2", MINUTE);
        LineChartSeries newSeries3 = generateSeries("series3", SECOND);

        _model.addSeries(newSeries1);
        _model.addSeries(newSeries2);
        _model.addSeries(newSeries3);

        _model.getAxis(AxisType.Y).setMin(Long.valueOf(0));
        DateAxis xAxis = new DateAxis();
        xAxis.setTickFormat("%H:%M:%S");
        xAxis.setMin("2017-12-07 17:50:00");
        xAxis.setMax("2017-12-07 18:49:00");
        _model.getAxes().put(AxisType.X, xAxis);
    }


    private LineChartSeries generateSeries(String name, int increment) {
        LineChartSeries series = new LineChartSeries(name);
        for (long i = 1512690600000L; i < 1512694140000L; i += increment) {
            series.set(_timer.formattedTime(i), Long.valueOf(new Random().nextInt(100)));
        }
        series.setFill(true);
        series.setShowMarker(false);
        return series;
    }

If setStacked is set to false, then the same series data works fine, i.e. the chart does render in that case.

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

08 Dec 2017, 19:37

are you sure each series has an entry for each 'tick'? not one missing?

dparasam
Posts: 9
Joined: 17 Nov 2016, 00:20

21 Dec 2017, 23:52

Like in my example posted, the three series have different number of data points.

Is it a requirement for all series to have the same number of data points? by setting non-existent entries with zeros?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 21 guests