我想在我的PrimeFaces (v5.3)图表上画一些额外的线,尤其是在线性图上。查看jqPlot示例(PrimeFaces使用jqPlot绘制图表)此示例显示了我想要做的事情。
我使用了这个答案中描述的方法。通过设置扩展程序,我能够运行自己的JavaScript函数,从而允许我更改不同类型的配置。
创建模式时的Java代码:
JavaScript函数正在被调用,因为背景实际上已经改变了,但我看不到任何变化。我尝试使用画布覆盖层。以下是示例的输出:
我知道PrimeFaces附带的jqPlot版本不包括覆盖插件。因此,我下载了最新的jqPlot版本,并在我的脚本中包含了覆盖插件(它由JSF包含)。但我可能会错过一些东西,或者在使用此插件时采取错误的方法。
Firefox Web控制台报告缺少jQuery。我还尝试了包括jquery.min.js和jquery.jqplot.min.js(来自jqplot发行版),这消除了错误,但没有显示水平线。
如何包括jqplot插件?如何进一步调试此情况以查看出了什么问题?
我使用了这个答案中描述的方法。通过设置扩展程序,我能够运行自己的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函数正在被调用,因为背景实际上已经改变了,但我看不到任何变化。我尝试使用画布覆盖层。以下是示例的输出:
![Output of this example](https://istack.dev59.com/DF7KG.webp)
Firefox Web控制台报告缺少jQuery。我还尝试了包括jquery.min.js和jquery.jqplot.min.js(来自jqplot发行版),这消除了错误,但没有显示水平线。
如何包括jqplot插件?如何进一步调试此情况以查看出了什么问题?