我试图广泛搜索论坛和谷歌,但我在理解如何使这项工作上遇到问题:
PrimeFaces6
我有一个基于ShowCase教程的BarchartModel:CODE:SELECT ALL私有BarChartModel initStatusBarChart(){BarChartModel model = new BarChartModel();
ChartSeries statusMessages = new ChartSeries();
statusMessages.setLabel("Label"));
statusMessages.set("Some String 1", list1.size());
statusMessages.set("Some String 2", list2.size());
model.addSeries(statusMessages);
return model;
}
Run Code Online (Sandbox Code Playgroud)
问题是在渲染时,我得到工具提示的格式
"1,515"和"2,432",其中515和432分别是list1和list2的大小.
如何用值"Some String"1和2替换1和2?尝试过延长荧光笔并使用dataTipFormat,但没有成功.
小智 5
我使用图表模型的数据提示编辑器解决了这个问题(顺便说一下,使用Primefaces 6.1).我用它来堆积条形图.我需要在两个地方应用此解决方案:支持bean和JSF页面.
在支持bean中,我必须以这种方式设置JavaScript函数名称:
barModel.setDatatipEditor("chartDatatipEditor");
Run Code Online (Sandbox Code Playgroud)
我尝试使用JSF页面中相应的标记属性设置它但不起作用.
在JSF中我插入了这个JavaScript代码:
<script type="text/javascript">
function chartDatatipEditor(str, seriesIndex, pointIndex, plot) {
//console.log('chartDatatipEditor: '+str+" - "+seriesIndex+" - "+pointIndex);
var point = seriesIndex+','+pointIndex;
#{bean.datatipsJs}
}
</script>
Run Code Online (Sandbox Code Playgroud)
此JS函数将图表坐标作为参数.我将它们连接起来,以便以下JS代码变得更容易. seriesIndex是图表系列的索引.pointIndex是图表X刻度的索引.
要找出图表的正确值,您可以取消注释上面的console.log行.
插入的JS代码以这种方式在backing bean中构造:
private Map<String, String> chartDatatips;
public String getDatatipsJs() {
StringBuilder sb = new StringBuilder("switch ( point ) {\n");
for (String point : chartDatatips.keySet()) {
sb.append("case '").append(point).append("': return '").append(chartDatatips.get(point)).append("'; break;\n");
}
sb.append("default: return 'Unknown point'; break; }");
return sb.toString();
}
Run Code Online (Sandbox Code Playgroud)
地图chartDatatips将坐标点作为键(例如,"2,1")并将工具提示作为值.
在图表设置过程中,您显然必须使用有用的详细信息填充此地图;-)
像这样:
chartDatatips.put("2,5", "Label ...");
...
Run Code Online (Sandbox Code Playgroud)
希望这有帮助,如果你还没有解决这个问题.
〜亚历克斯
归档时间: |
|
查看次数: |
730 次 |
最近记录: |