带文本 x 轴的 graphael 条形图
我想知道如何制作一个简单的条形图,该条形图可能以天为 x 轴,值为“今天”和“昨天”,y 轴可能为“时间”,对应值为“1”和“2” '。我想我对如何将文本设置为 x 轴的值、如何显示 y 轴以及 rgaxis 到底做什么感到困惑...... (我找到了一个使用 axis = rgaxis(0,300,400,0,500,8,2)
的示例,我只知道它是 xpos
, ypos
,<代码>宽度,<代码>??,<代码>??数字刻度,<代码>??)。任何见解都会很棒!或者具有更功能齐全的条形图示例(标签等)的页面。谢谢。
I was wondering how I can make a simple bar chart that perhaps has day as the x-axis, with values 'today' and 'yesterday', and the y-axis as perhaps 'time' with corresponding values '1' and '2'. I guess I'm confused as to how to set text as the values for the x-axis, how to show the y axis, and what exactly r.g.axis does...
(I found an example using axis = r.g.axis(0,300,400,0,500,8,2)
and I only know it's the xpos
, ypos
,width
, ??
, ?? num ticks
, ??
). Any insight would be great! Or a page with more fully featured bar chart examples (labels, etc). Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
为了所有那些谷歌搜索的人:
x_start和y_start:轴文本距左下角的距离
x_width:结束位置沿 x 轴的文本
from 和 to:用于指定要使用的范围,而不是使用标签参数
steps:是数字刻度数 - 1
方向:似乎指定 x 轴与 y 轴
类型:是使用的刻度线类型。
这都是从源代码推断出来的。我想我现在会切换到带有文档的图表库......
For the sake of all those googling this:
x_start and y_start: distance of the axis text from the bottom left corner
x_width: position of the end of the text along the x axis
from and to: used to specify and range to use instead of using the labels argument
steps: is the number of ticks - 1
orientation: seems to specify x-axis vs. y-axis
type: is the type of tick mark used.
This was all deduced from the source code. I think I'll be switching to a charting library with documentation now...
当前代码(Raphaeljs 2.0)已更改,必须稍作修改才能使用 Raphael.g.axis 而不是 rgaxis:
The current code (Raphaeljs 2.0) has changed and has to be slightly adapted to use Raphael.g.axis instead of r.g.axis:
你走在正确的轨道上。您使用 g.axis ,用于设置文本的位置参数可在“文本”参数(位置)中找到,并使用“方向”参数切换 y。我在这里添加了一个示例,
带有文本 x 轴的条形图
You're on the right track. You use g.axis and the positional arguments for setting the text is found in the 'text' arg (positional) and for toggling the y using the 'orientation' args. I added an example here,
Barchart with text x-axis
阅读了这个问答和十几个类似的问答,我仍然无法让 gRaphaël 显示条形图的正确标签。这些食谱似乎都引用了该库的旧版本,或者不再存在的 github 页面。 gRaphaël 产生了一些漂亮的输出——但它的文档还有很多不足之处。
然而,我能够结合使用 Firebug 和 Inspect This Element 来跟踪代码并查看它生成的内容。深入研究条形图对象,所需的几何图形就在那里。为了避免其他人的挫败感,我解决了这个问题:
您可以对 labelBarChart() 进行一些小的清理,但这基本上可以完成工作。
Reading this Q&A and a dozen like it, I still could not get gRaphaël to show proper labels for a bar chart. The recipes all seemed to refer to older versions of the library, or to github pages that are no longer there. gRaphaël produces some great looking output--but its docs leave much to be desired.
I was, however, able to use a combination of Firebug and Inspect This Element to follow the code and see what it produced. Diving into the barchart object, the required geometry is right there. To save others the frustration, here's how I solved the problem:
There are a bunch of little cleanups you could do to
labelBarChart()
, but this basically gets the job done.这是我编写的用于添加标签的函数。它不是特别优雅,但它会添加标签:
用法如下:
Here's a function I wrote for adding the labels. It's not particularly elegant but it will add the labels:
Usage is as follows:
我想提出
这导致代码:
我刚刚用两个堆叠的值数组对其进行了测试。
I would like to propose a solution of an issue of the labelBarChart function proposed by Jonathan Eunice.
considering stacked bar-graphes (or other bar-graphes with more than one array of values), I added a test on bc.bars[0] in case the bc.bars.length means the number of arrays of values stacked.
This lead to the code :
I just tested it with 2 arrays of values stacked.