简体   繁体   English

primefaces barChart costum x-axes

[英]primefaces barChart costum x-axes

I have p:barchart graph in my application similar to the second barchart on the showCase: http://www.primefaces.org/showcase/ui/barChart.jsf 我的应用程序中有p:barchart图,类似于showCase上的第二个条形图: http//www.primefaces.org/showcase/ui/barChart.jsf

<p:barChart id="horizontal" value="#{chartBean.categoryModel}" legendPosition="se" style="height:300px"  
            title="Horizontal Bar Chart" orientation="horizontal" min="0" max="200"/>

how can I customize the Numbers on my X-axis. 如何在X轴上自定义数字。 I want to format the x-axis to use only Integers. 我想格式化x轴只使用整数。

thanks in advance. 提前致谢。

Try this (not tested) : 试试这个(未经测试)

<p:barChart extender="ext" id="horizontal" value="#{chartBean.categoryModel}" legendPosition="se" style="height:300px"  
    title="Horizontal Bar Chart" orientation="horizontal"/>

In you js add this 在你js添加这个

function ext() {
   this.cfg.seriesDefaults = { 
       useSeriesColor: true, 
       min: 0, 
       max: 200, 
       tickInterval: 20, 
       tickOptions: { 
           formatString: '%d' 
       } 
   };
}

or this x axis only : 或仅此x轴:

function ext() {
   this.cfg.axes = {
       xaxis:
       {
           tickInterval: 20,
           tickOptions: { 
               formatString: '%d' 
           } 
       }
   };
}

You can try playing with tickInterval ... 您可以尝试使用tickInterval ...


Straight from the PrimeFaces Userguide 直接来自PrimeFaces用户指南

Extender 扩展

Charts provide high level access to commonly used jqplot options however there are many more customization options available in jqplot. 图表提供对常用jqplot选项的高级访问,但jqplot中有更多自定义选项可用。 Extender feature provide access to low level apis to do advanced customization by enhancing this.cfg object, here is an example to increase shadow depth of the line series; 扩展器功能通过增强this.cfg对象提供对低级api的访问以进行高级自定义,这里是增加线系列阴影深度的示例;

<p:lineChart value="#{bean.model}" extender="ext" />


function ext() {
    //this = chart widget instance
    //this.cfg = options
    this.cfg.seriesDefaults = {
        shadowDepth: 5
    };
}

Refer to jqPlot docs for the documentation of available options; 有关可用选项的文档,请参阅jqPlot文档; http://www.jqplot.com/docs/files/jqPlotOptions-txt.html Converter http://www.jqplot.com/docs/files/jqPlotOptions-txt.html转换器

your extender function could be like this 你的扩展功能可能是这样的

    function customExtender() {
        this.cfg.axes.xaxis.tickOptions = {
            formatString : '%d'
        };
        this.cfg.axes.xaxis.tickInterval = 1;
    }

I had the same problem and this works great, I based on Daniel's Answer and some other code. 我有同样的问题,这很有效,我基于丹尼尔的答案和其他一些代码。 This way it just format the desired axis, not both. 这样它只是格式化所需的轴,而不是两者。

In you js add this 在你js添加这个

function ext() {
    this.cfg.axes.xaxis.tickOptions.formatString = '%d';
}

You can set format to axis from your @ManagedBean class using the following code: 您可以使用以下代码从@ManagedBean类将格式设置为axis:

Axis xAxis = categoryModel.getAxis(AxisType.X);
xAxis.setTickFormat("%.0f");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM