今天我想尝试一下新的PrimeFaces 3.4.RC1版本。 对于图表来说,有一个新属性叫做datatipFormat。
我想要在折线图中仅显示值(y轴)作为datatip。 像这样:
<p:lineChart value="#{...}" datatipFormat="y-value"/>
我该如何仅显示这部分内容?我找不到一个使用模板字符串的例子。
最好的问候, Veote
今天我想尝试一下新的PrimeFaces 3.4.RC1版本。 对于图表来说,有一个新属性叫做datatipFormat。
我想要在折线图中仅显示值(y轴)作为datatip。 像这样:
<p:lineChart value="#{...}" datatipFormat="y-value"/>
我该如何仅显示这部分内容?我找不到一个使用模板字符串的例子。
最好的问候, Veote
Primefaces使用jqPlot图表库。在那里我找到了以下条目:
Highlighter.formatString
我尝试了(来自Primefaces Showcase的示例):
<p:lineChart id="basic" value="#{userBean.categoryModel}" legendPosition="ne"
datatipFormat="#{userBean.datatipFormat}" title="Basic Bar Chart" min="0"
max="200" style="height:300px"/>
用户实体类
public String getDatatipFormat(){
return "<span style=\"display:none;\">%s</span><span>%s</span>";
}
通过这个小技巧,只显示 y 轴。
extender
属性来覆盖默认的绘图选项。例如:<script type="text/javascript">
function customExtender() {
this.cfg.highlighter = {
useAxesFormatters: false,
tooltipAxes: 'y'
}
}
</script>
...
<p:lineChart extender="customExtender" value="..." />
其他可用的jqplot选项可以在此处找到:http://www.jqplot.com/docs/files/jqPlotOptions-txt.html,但请注意,该文档称其已过时。
BarChartModel()的提示:
public String getDatatipFormatX() {
return "<font size=4 color=blue><span style=\"display:none;\">%s</span><span>%s</span></font>";
}
HorizontalBarChartModel()的提示:
public String getDatatipFormatY() {
return "<font size=4 color=blue><span>%s</span><span style=\"display:none;\">%s</span></font>";
}
使用示例:
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...
}
<p:chart type="bar" model="#{chartBean.myBarChartModel}" />
<p:chart type="bar" model="#{chartBean.myHorizontalBarChartModel}" />
datatipFormat使用sprintf格式化字符串用于工具提示,因此您可以仅打印第二个参数(y轴):
<p:lineChart value="#{...}" datatipFormat="%2$d"/>
yourBarChartModel.setDatatipFormat("%.0s%s");