我正在使用 Flot 构建 Rails 3.2.11 应用程序。我想使用 Prawn 在 PDF 中呈现我的 Flot 图表。我的 Flot 图表在浏览器中呈现良好。我可以很好地创建 Prawn PDF(虽然还没有图表图像)。
我想使用 Flot 画布插件在画布上渲染我的轴等,以便在我使用.getCanvas()和.toDataURL()方法将图像数据 Ajax 到服务器时包含它们,但我似乎不能让它工作。
我正在使用 jquery.flot.min.js 0.8.0 和 jquery.flot.canvas.min.js(未指明版本)。在 Chrome 控制台中,我看到两者都在加载。
我的 Coffeescript 看起来像这样:
temp_plot = $.plot $("#barchart"), [
data: $("#barchart").data("bardata")
bars:
show: true
barWidth: (365/12)*24*60*60*1000*0.8
align: 'center'
],
xaxis:
mode: "time"
timeformat: "%b"
tickSize: [1, "month"]
yaxis:
position: 'right'
labelWidth: '40'
reserveSpace: true
canvas: true
barchart_canvas = temp_plot.getCanvas()
我能够看到 Ajax 有效负载,它确实是 Flot 图表画布,只是没有轴等。我感谢任何建议。谢谢!
为了更加清楚,作为 Javascript 的代码如下所示:
var barchart_canvas, temp_plot;
temp_plot = $.plot($("#barchart"), [
{
data: $("#barchart").data("bardata"),
bars: {
show: true,
barWidth: (365 / 12) * 24 * 60 * 60 * 1000 * 0.8,
align: 'center'
}
}
], {
xaxis: {
mode: "time",
timeformat: "%b",
tickSize: [1, "month"]
},
yaxis: {
position: 'right',
labelWidth: '40',
reserveSpace: true
},
canvas: true
});
barchart_canvas = temp_plot.getCanvas();
更新 - 成功
我将 Flot 更新为 0.8.1,并包含了 0.8.1 .zip 存档中的 jquery.flot.canvas.js 文件。(我在使用 Flot 0.8.0 和 jquery.flot.js 0.8.1 的插件时遇到了一些奇怪的渲染行为,所以要小心。)
现在我的轴呈现在画布上。伟大的!感谢弗洛特诸神!