Question

I use jQplot with primeFaces.

I would like a date formatter for the CategoryAxis (dates are in millis).

I found different solutions on Stack but the problem seems to be my ticks : they are adds "after" the creation and options/format are not taking into consideration.

ticks: this.cfg.categories,

I tested with datetickformatter, a custom datetickformatter, CanvasAxisTickRenderer, and edition of CanvasAxisTickRenderer. In vain.

this.cfg.axes = {
    xaxis: {
        renderer: $.jqplot.CategoryAxisRenderer,
        rendererOptions: {
            tickRenderer: $.jqplot.CanvasAxisTickRenderer
        },
        tickOptions: {
            formatString: '%a.',
            fontSize:'7pt',
        },
        ticks: this.cfg.categories,
    },

Thanks, Ju.

Was it helpful?

Solution

I have discovered the same problem using a combination of CategoryAxisRenderer and CanvasTickRenderer. I came up with the solution of formating the categories by hand in javascript and then passing them to the Renderer. In your case you could use the following as extender for your primefaces chart:

function extender() {

var millis = this.cfg.categories;
var dates = new Array(categories.length);

for (var i = 0; i < categories.length; i++) {
    dates[i] = new Date(categories[i]).toLocaleDateString();
}

this.cfg.axes = {
    xaxis : {
        renderer : $.jqplot.CategoryAxisRenderer,
        rendererOptions : {             
            tickRenderer : $.jqplot.CanvasAxisTickRenderer,
            tickOptions : {
                fontSize:'7pt'                                  
            },
            ticks : dates
        }
    }
};
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top