获取数据并将其放入图表中的最佳方法?
我想从与下面的表格几乎完全相同的表格中获取数据,但将其放在折线图中。日期值将位于 Y 轴上,而 XP 值将绘制在 X 轴上。由于每个用户的数字各不相同,我想我需要一种方法来使绘制的每个点之间的距离“相对”。
示例表 http://img687.imageshack.us/img687/4175/tablel.png< /a>
有什么建议吗?
I want to take data from a table that'll be almost exactly similiar to the one below, but have it in a line graph. The date values would be on the Y-axis, and it would plot the XP values on the X-axis. Since the numbers for each user vary, I'd need a way to make the distance between each point plotted "relative", I guess.
Example table http://img687.imageshack.us/img687/4175/tablel.png
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您想生成图表的静态图像,可以使用 Libchart 或 <用于 PHP 的 href="http://pchart.sourceforge.net/" rel="nofollow noreferrer">pChart。
If you want to generate a static image of the chart you could use Libchart or pChart for PHP.
最好从数据源获取数据,而不是从渲染的表中获取数据。无论如何,这是两个独立的问题:如何从表中获取数据以及如何绘制图表。
用 PHP 绘制图表非常简单。 HTML/CSS 可用于绘制条形,PHP 可用于计算条形长度。
It's better to get the data from the data source, not from the rendered table. Anyway it's two separate questions: how to take data from a table and how to draw a graph.
Drawing a chart in PHP is pretty easy. HTML/CSS can be used to draw a bar and PHP to calculate the bar length.
或者,如果您想走 JavaScript 路线,也许Raphaël。
Or if you want to go the JavaScript route, maybe Raphaël.
我会选择 HighCharts。
I would go for HighCharts.
如果您使用的是 linux/unix 平台,您可能已经安装了 Gnuplot。 Gnuplot 可以获取绘图文件和数据文件并生成图像,因此:
History.gnuplot,需要首先生成:
假设已经生成了数据文件
rawr_satch_xphistory.dat
,格式如下:人们还为大多数语言编写了 Gnuplot 接口,例如 PHP-GNUPlot。 Gnuplot 脚本可能非常复杂,您可以绘制多个变量等。
If you're using a linux/unix platform, you probably already have Gnuplot installed. Gnuplot can take a plot file and a datafile and generate an image, thus:
History.gnuplot, which needs to be generate first:
Which assumes a data file
rawr_satch_xphistory.dat
has already been generated, formatted thus:People have also written interfaces into Gnuplot for most languages, for example PHP-GNUPlot. Gnuplot scripts can be quite complex, and you could plot multiple variables, etc.
我使用并完全推荐 Google 图表工具 API。如果您正在寻找简单的折线图,他们提供了一个非常简单的 API,您可以调用该 API,无需安装或配置。有些文档令人困惑,但我已经能够通过一点耐心弄清楚了。
所需要的只是一个 IMG 标签,并使用正确的参数将 src 指向 Google URL。
如果您想稍后提供更多功能,它们还有一个更具交互性的 Javascript 库。
I use and fully recommend the Google Chart Tools API. If you're looking for a simple line-graph, they provide a very simple API that you can call that requires no installation or configuration. Some of the documentation is confusing, but I've been able to figure it out with a little bit of patience.
All that is required is an IMG tag and point the src to the Google URL with the right parameters.
They also have a more interactive Javascript library if you want to provide more functionality later on.
我使用了 PHP 中的以下内容:Google 图表、打开 Flash 图表, YUI 图表 (Flash) 和 AMCharts (也闪光)。
它们都非常易于使用,并且各有优缺点。如果您想在一页上显示多个图表,请不要使用基于 Flash 的图表。事实证明,浏览器无法同时显示十几个 Flash 图表。 AMCharts 可能是功能最丰富的,但可用的选项取决于您选择的图表包,并且配置非常复杂。
I've used the following from PHP: Google Charts, Open Flash Chart, YUI charts (Flash), and AMCharts (also Flash).
They're all pretty easy to use and all have their pros and cons. If you want to show more than a single graph on one page, don't use Flash-based charts. It turns out browsers have trouble displaying a dozen Flash charts all at once. AMCharts is probably the most feature rich, but the options available depend on which of their chart packages you select, and configuration is pretty complex.