Date format jqplot categoryaxisrenderer after ticks add

只谈情不闲聊 提交于 2019-12-24 04:21:50

问题


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.


回答1:


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
        }
    }
};
}


来源:https://stackoverflow.com/questions/21182736/date-format-jqplot-categoryaxisrenderer-after-ticks-add

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!