PrimeFaces 3.4 Charts datatipFormat

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

today I wanted to try the new PrimeFaces release 3.4.RC1. For charts there is a new attribute called datatipFormat.

I want to show only the value (y-axis) in a line chart as datatip. Like this:

What do I have to do to show only this? I could not find an example with a template String.

Best Regards Veote

回答1:

Primefaces uses a jqPlot Library for Charts. There I found the following entry:

Highlighter.formatString

I tried (example from Primefaces Showcase):

   

UserBean

public String getDatatipFormat(){    return "%s%s"; } 

and with this little trick is only y-axis displays.



回答2:

You can use the extender property of all PrimeFaces chart tags to override default plot options. Example:

 ... 

Other available jqplot options can be found here: http://www.jqplot.com/docs/files/jqPlotOptions-txt.html but please note that the document says it is out of date.



回答3:

datatipFormat uses sprintf to format the string for the tooltip, so you can print only the second parameter (y-axis):



回答4:

Tip for BarChartModel():

public String getDatatipFormatX() {     return "%s%s"; } 

Tip for HorizontalBarChartModel():

public String getDatatipFormatY() {     return "%s%s"; } 

Examples of usage:

private void MyCharts(){  //get data (from database, for example) to be displayed  myBarChartModel = new BarChartModel(); myHorizontalBarChartModel = new HorizontalBarChartModel();  ChartSeries verticalSeries = new ChartSeries("verticalSeries"); ChartSeries horizontalSeries = new ChartSeries("horizontalSeries");  myBarChartModel.addSeries(verticalSeries); myHorizontalBarChartModel.addSeries(horizontalSeries);  myBarChartModel.setDatatipFormat(getDatatipFormatX()); myHorizontalBarChartModel.setDatatipFormat(getDatatipFormatY()); //other chart settings...  } 

Then, in JSF page:



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