PrimeFaces 3.4 Charts datatipFormat

今天我想尝试新的PrimeFaces版本3.4.RC1。 对于图表,有一个名为datatipFormat的新属性。

我想仅在折线图中显示值(y轴)作为datatip。 喜欢这个:

我该怎么做只显示这个? 我找不到一个带有模板String的例子。

最好的问候Veote

Primefaces使用jqPlot库进行图表。 在那里我找到了以下条目:

Highlighter.formatString

我试过(来自Primefaces Showcase的例子):

   

的UserBean

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

而这个小技巧只有y轴显示。

您可以使用所有PrimeFaces图表标记的extender属性来覆盖默认打印选项。 例:

  ...  

其他可用的jqplot选项可以在这里找到: http ://www.jqplot.com/docs/files/jqPlotOptions-txt.html但请注意文档说它已过时。

datatipFormat使用sprintf格式化工具提示的字符串,因此您只能打印第二个参数(y轴):

  

BarChartModel()提示:

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

Horizo​​ntalBarChartModel()的提示:

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

用法示例:

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

然后,在JSF页面中:

   

您只能显示x值的前0个字符(%。0s),隐藏它的方法。 在它背后,你可以用sprintf格式的y值做你想要的。

 yourBarChartModel.setDatatipFormat("%.0s%s");