Lin Wang
Lin Wang

Reputation: 11

Newline character %n in jqplot.dateAxisRenderer tick format options does not work

I am using Netbeans/JSF/Primefaces6.1 to develop a web application, in which I want to display a line chart with date/time X-Axis. I set the time format according to the following link, http://www.jqplot.com/docs/files/plugins/jqplot-dateAxisRenderer-js.html

I want to use a new line character %n to render the date as two lines

2014-01-01
02:10:52

instead of only one line

2014-01-01 02:10:52

However, the %n does not work and the latter always renders as follows, which means the %n renders as a space and the date/times overlap. enter image description here

Either I use the Primefaces DateAxis class as follows

private LineChartModel initLinearModel() {
    LineChartModel model = new LineChartModel();
    series.setLabel("Series 1");
    model.setExtender("lineChartExtender");
    model.addSeries(series);

    series.set("2014-01-01 00:10:50", 51);
    series.set("2014-01-06 01:10:51", 22);
    series.set("2014-01-12 02:10:52", 65);
    series.set("2014-01-18 03:10:53", 74);
    series.set("2014-01-24 04:10:54", 24);
    series.set("2014-01-30 05:10:55", 51);

    model.getAxis(AxisType.Y).setLabel("Values");
    DateAxis axis = new DateAxis("Dates");
    axis.setMax("2014-02-01");
    axis.setTickFormat("%Y-%m-%d%n%H:%M:%S");
    model.getAxes().put(AxisType.X, axis);

    return model;
}

or use the low-level jqPlot configuration in the extender as follows, it does not work.

    function lineChartExtender() {
        this.cfg.axes = {
            xaxis : {
                renderer : $.jqplot.DateAxisRenderer,
                tickRenderer : $.jqplot.CanvasAxisTickRenderer,
                tickOptions : {
                    formatString : "%b %#d %n %H:%M:%S",
                    angle : -30
                },
                drawMajorGridlines : false
            },
            yaxis : {
                // Other Options for Y Axis
            }
        };
    }

So how can I let the newline character %n in jqPlot work properly?

Upvotes: 0

Views: 561

Answers (1)

user8691384
user8691384

Reputation:

I found that if I removed tickRenderer : $.jqplot.CanvasAxisTickRenderer from xaxis, then the newline formats as documented.

Upvotes: 0

Related Questions