我是 gRaphael 的新手,而不是能够取消选择源代码的铁杆 JS 开发人员,而且关于如何正确使用它的文档似乎为零。
我很想在我的应用程序上启动并运行点图,但对 x 和 y 值如何在图表画布上绘制点感到困惑。
我一直在使用http://g.raphaeljs.com/dotchart.html上的演示作为图表的基础。但是,当我修改数据集时,我会丢失图表中的所有点。
我不认为我理解画布中的点与 x 和 y 之间的关系。
有人可以告诉我如何在下面的代码中包含我从数据库返回的数据吗?
返回的数据是一个包含 23 个元素的数组,范围从 8 到 56。
<script type="text/javascript" charset="utf-8">
window.onload = function () {
var r = Raphael("holder2"),
xs = <%= chart_xs(@weeks) %>,
ys = <%= chart_ys(@weeks) %>,
data = <%= chart_data(@weeks) %>,
axisy = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
axisx = ["12am", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12pm", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"];
r.g.txtattr.font = "11px 'Fontin Sans', Fontin-Sans, sans-serif";
r.g.dotchart(10, 10, 620, 260, xs, ys, data, {
symbol: "o",
max: 10,
heat: true,
axis: "0 0 1 1",
axisxstep: 23,
axisystep: 6,
axisxlabels: axisx,
axisxtype: " ",
axisytype: " ",
axisylabels: axisy
}).hover(function () {
this.tag = this.tag || r.g.tag(this.x, this.y, this.value, 0, this.r + 2).insertBefore(this);
this.tag.show();
}, function () {
this.tag && this.tag.hide();
});
};
</script>
像这样的输出:
<script type="text/javascript" charset="utf-8">
window.onload = function () {
var r = Raphael("holder2"),
xs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
ys = [220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220],
data = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20],
axisy = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
axisx = ["12am", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12pm", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"];
r.g.txtattr.font = "11px 'Fontin Sans', Fontin-Sans, sans-serif";
r.g.dotchart(10, 10, 620, 260, xs, ys, data, {symbol: "o", max: 10, heat: true, axis: "0 0 1 1", axisxstep: 23, axisystep: 6, axisxlabels: axisx, axisxtype: " ", axisytype: " ", axisylabels: axisy}).hover(function () {
this.tag = this.tag || r.g.tag(this.x, this.y, this.value, 0, this.r + 2).insertBefore(this);
this.tag.show();
}, function () {
this.tag && this.tag.hide();
});
};
</script>
Frederico,你能解释一下为什么这个图表在屏幕上什么都没有显示吗?如果你的解释成立,那么 23 个数据点中的每一个都应该在画布上的一条连续线上表示:
<script type="text/javascript" charset="utf-8">
window.onload = function () {
var r = Raphael("holder"),
xs = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
ys = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
data = [294, 300, 204, 255, 348, 383, 334, 217, 114, 33, 44, 26, 41, 39, 52, 17, 13, 2, 0, 2, 5, 6, 64],
axisy = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
axisx = ["12am", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12pm", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"];
r.g.txtattr.font = "11px 'Fontin Sans', Fontin-Sans, sans-serif";
r.g.dotchart(10, 10, 620, 260, xs, ys, data, {symbol: "o", max: 10, heat: true, axis: "0 0 1 1", axisxstep: 23, axisystep: 6, axisxlabels: axisx, axisxtype: " ", axisytype: " ", axisylabels: axisy}).hover(function () {
this.tag = this.tag || r.g.tag(this.x, this.y, this.value, 0, this.r + 2).insertBefore(this);
this.tag.show();
}, function () {
this.tag && this.tag.hide();
});
};
</script>
但什么都没有显示。这是我的数据遇到的问题,它与这个硬编码脚本中的数据大致对齐。那么,您认为如何正确显示原始输出中的数据(请参阅问题)?