java PrimeFaces 3.4 图表数据提示格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12050008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PrimeFaces 3.4 Charts datatipFormat
提问by veote
today I wanted to try the new PrimeFaces release 3.4.RC1. For charts there is a new attribute called datatipFormat.
今天我想尝试新的 PrimeFaces 版本 3.4.RC1。对于图表,有一个名为 datatipFormat 的新属性。
I want to show only the value (y-axis) in a line chart as datatip. Like this:
我只想将折线图中的值(y 轴)显示为数据提示。像这样:
<p:lineChart value="#{...}" datatipFormat="y-value"/>
What do I have to do to show only this? I could not find an example with a template String.
我需要做什么才能只显示这个?我找不到带有模板字符串的示例。
Best Regards Veote
最好的问候
回答by maciek
Primefaces uses a jqPlot Library for Charts. There I found the following entry:
Primefaces 为图表使用 jqPlot 库。在那里我找到了以下条目:
Highlighter.formatString
I tried (example from Primefaces Showcase):
我试过的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"/>
UserBean
用户豆
public String getDatatipFormat(){
return "<span style=\"display:none;\">%s</span><span>%s</span>";
}
and with this little trick is only y-axis displays.
有了这个小技巧,只有 y 轴显示。
回答by Rafa?
You can use the extender
property of all PrimeFaces chart tags to override default plot options. Example:
您可以使用extender
所有 PrimeFaces 图表标签的属性来覆盖默认绘图选项。例子:
<script type="text/javascript">
function customExtender() {
this.cfg.highlighter = {
useAxesFormatters: false,
tooltipAxes: 'y'
}
}
</script>
...
<p:lineChart extender="customExtender" value="..." />
Other available jqplot options can be found here: http://www.jqplot.com/docs/files/jqPlotOptions-txt.htmlbut please note that the document says it is out of date.
可以在此处找到其他可用的 jqplot 选项:http://www.jqplot.com/docs/files/jqPlotOptions-txt.html但请注意该文档说它已过时。
回答by mark0z
datatipFormat uses sprintf to format the string for the tooltip, so you can print only the second parameter (y-axis):
datatipFormat 使用 sprintf 来格式化工具提示的字符串,因此您只能打印第二个参数(y 轴):
<p:lineChart value="#{...}" datatipFormat="%2$d"/>
回答by jMarcel
Tip for BarChartModel():
BarChartModel() 的提示:
public String getDatatipFormatX() {
return "<font size=4 color=blue><span style=\"display:none;\">%s</span><span>%s</span></font>";
}
Tip for HorizontalBarChartModel():
HorizontalBarChartModel() 的提示:
public String getDatatipFormatY() {
return "<font size=4 color=blue><span>%s</span><span style=\"display:none;\">%s</span></font>";
}
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:
然后,在 JSF 页面中:
<p:chart type="bar" model="#{chartBean.myBarChartModel}" />
<p:chart type="bar" model="#{chartBean.myHorizontalBarChartModel}" />
回答by heiwil
You can show only the first 0 characters of the x value (%.0s), what means to hide it. Behind it you can do what you want with the y value in sprintf format.
只能显示x值的前0个字符(%.0s),隐藏是什么意思。在它后面,您可以使用 sprintf 格式的 y 值执行您想要的操作。
yourBarChartModel.setDatatipFormat("%.0s%s");