number scale on primefaces charts

让人想犯罪 __ 提交于 2020-01-05 07:22:31

问题


When we create a primefaces chart then it shows number scale in decimal points. I want to show without decimal places like simple munbers.Is there a way?
Thanks


回答1:


Update:

While the workaround posted below still works I found a more proper solution to do this. Number scale can be formatted trough extender function:

<p:barChart value="#{testClazz.categoryModel}" legendPosition="ne"
            widgetVar="barChartObj1" extender="ext1"/>

place the following function between the <head></head> tags on your page:

<script type="text/javascript">
    function ext1() {
        this.cfg.axes.yaxis.tickOptions = {
            formatString : '%d'
        };
    }
</script>

After experimenting a bit with jqPlot I found out that if you reset the axes after the plotting has finished the decimals after the decimal point are cleared. If your barChart is definied like this:

<p:barChart id="basicPlot" value="#{testClazz.categoryModel}" 
    legendPosition="ne" widgetVar="barChartObj"
    title="Basic Bar Chart" min="0" max="270"/>

call the following function after the page load is finished:

<script type="text/javascript">
    $(document).ready( function() {
        setTimeout(formatAxisNumbers, 500);
    });
    function formatAxisNumbers() {
        window.barChartObj.plot.resetAxesScale();
        window.barChartObj.plot.replot();
    }
</script>

Note that instead of resetting both axes with resetAxesScale you can reset x or y separately by doing:

window.barChartObj.plot.axes.xaxis.resetScale();

or

window.barChartObj.plot.axes.yaxis.resetScale();

You can also expriment with decreasing the timeout to smaller numbers to achieve smoother replot. For other options see the jqPlot documentation.

Tested in Google Chrome 22.0.1229.94 (Official Build 161065).



来源:https://stackoverflow.com/questions/12739615/number-scale-on-primefaces-charts

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