PrimeFaces - customise Date Chart

后端 未结 1 1136
太阳男子
太阳男子 2020-12-17 01:19

I am using PrimeFaces 3.4.1 to plot time chart (Date on x-axis, int value on y-axis).

At the moment I have something like that:

xhtml:

相关标签:
1条回答
  • 2020-12-17 02:18

    In Java, fill your LineChartSeries objects with times in milliseconds using Date#getTime().

    On the facelets side, download from jqPlot site and import the following jqPlot plugins:

    <h:outputScript name="Javascript/jqplot.canvasAxisTickRenderer.js" />
    <h:outputScript name="Javascript/jqplot.canvasAxisTickRenderer.min.js" />
    <h:outputScript name="Javascript/jqplot.dateAxisRenderer.js" />
    <h:outputScript name="Javascript/jqplot.dateAxisRenderer.min.js" />
    

    And use this js extender for p:lineChart component:

    function chartExtender() {
        this.cfg.axes = {
            xaxis : {
                renderer : $.jqplot.DateAxisRenderer, 
                rendererOptions : {
                    tickRenderer:$.jqplot.CanvasAxisTickRenderer
                },
                tickOptions : { 
                    fontSize:'10pt',
                    fontFamily:'Tahoma', 
                    angle:-40
                }
            },
            yaxis : {
                rendererOptions : {
                    tickRenderer:$.jqplot.CanvasAxisTickRenderer
                },
                tickOptions: {
                    fontSize:'10pt', 
                    fontFamily:'Tahoma', 
                    angle:30
                }
            }               
        };
        this.cfg.axes.xaxis.ticks = this.cfg.categories;
    }
    

    Useful links:

    http://forum.primefaces.org/viewtopic.php?f=3&t=25289#p79916

    http://forum.primefaces.org/viewtopic.php?f=3&t=23891&p=78637#p78637

    0 讨论(0)
提交回复
热议问题