【发布时间】:2016-06-28 12:29:17
【问题描述】:
我想在我的 PrimeFaces (v5.3) 图表上画一些额外的线条,尤其是在折线图上。查看 jqPlot 示例(PrimeFaces 使用 jqPlot 绘制图表),this example 显示了我想要做的事情。
我使用了this answer中描述的方法。
通过设置扩展器,我可以运行我自己的 javascript 函数,这允许我更改不同类型的配置。
创建模式时的Java:
private LineChartModel initLinearModel()
{
LineChartModel model = new LineChartModel();
model.setExtender("chartExtender");
LineChartSeries series1 = new LineChartSeries();
series1.setLabel("Series 1");
series1.set(1, 2);
series1.set(2, 1);
series1.set(3, 3);
series1.set(4, 6);
series1.set(5, 8);
model.addSeries(series1);
return model;
}
Xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:outputScript library="jqplot-plugin"
name="jqplot.canvasOverlay.min.js" />
<h:outputScript library="js" name="extra_config.js" />
<h:head>
<title>Chart</title>
</h:head>
<h:body>
<p:chart type="line" model="#{primeChart.lineModel1}"
style="height:300px;" />
</h:body>
</html>
Javascript 函数:
function chartExtender() {
this.cfg.grid = {
background : '#888888',
}
this.cfg.canvasOverlay = {
show: true,
objects: [{horizontalLine: {
name: 'pebbles',
y: 3,
lineWidth: 2,
color: 'rgb(255, 55, 124)',
shadow: true,
lineCap: 'butt',
xOffset: 0
}}]
};
}
正在调用 javascript 函数,因为背景实际上已更改但我没有看到任何更改我尝试使用画布覆盖。这是示例的输出:
我了解 PrimeFaces 附带的 jqPlot 版本不包含叠加插件。所以我已经下载了最新的 jqPlot 版本并在我的脚本中包含了覆盖插件(它被 JSF 包含)。但是我很可能错过了一些东西,或者在使用这个插件时采取了正确的方法。
firefox webconsole 报告它缺少 jquery。我还尝试包含 jquery.min.js 和 jquery.jqplot.min.js(来自 jqplot 版本),这消除了错误,但不显示水平线。
如何包含 jqplot 插件?如何进一步调试这种情况以查看问题所在?
【问题讨论】:
标签: jsf-2 primefaces jqplot