Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date format jqplot categoryaxisrenderer after ticks add

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.

like image 282
Julien Malige Avatar asked Jul 18 '26 13:07

Julien Malige


1 Answers

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
        }
    }
};
}
like image 70
nilsfried Avatar answered Jul 20 '26 02:07

nilsfried



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!