如何在PHP中创建图形 [英] How to create graph in PHP

查看:73
本文介绍了如何在PHP中创建图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在php中实现图形。

使用谷歌图表可能有可能但它是在javascript代码中。

PHP中是否有用于创建图表的库文件?



我是什么尝试过:



我试过谷歌图表,但它是用javascript。

How to implement a graph in php.
Using Google chart it may be possible But it's in javascript code.
Is there any library file are available in PHP for creating a graph ?

What I have tried:

I tried google chart but it's in javascript .

推荐答案

分离关注点在这里发挥作用。



图表是表示层,应该是最后要做的事情之一;最简单的方法是通过实际网页上的JavaScript。



PHP是服务器端,将扮演业务层的角色以及数据层



那你怎么申请这个?

你得到所有您的数据并将此数据处理到您要在网页上显示的数据集中。这个数据集可以通过内联PHP直接注入HTML。

另一种选择是将这个数据处理放在一个单独的PHP脚本中并通过AJAX调用它。

无论您选择哪种上述方法;一旦该数据集可用,您就可以使用JavaScript来处理数据集并使用您选择的库构建图表。
Separation of Concerns comes into play here.

The Chart is presentation layer and should be one of the last things to do; easiest way to do it would be via JavaScript on the actual webpage.

PHP is server-side, and will play the roles of the Business Layer as well as the Data Layer.

So how do you apply this?
You get all of your data and process this data into the data-set you want to display on the web page. This data-set can be injected directly into the HTML via inline PHP.
Another option would be to have this data-processing in a separate PHP script and call it via AJAX.
Regardless of which of the above methods you choose; once that data-set is available you use JavaScript to work through the data-set and build the chart using the library of your choice.


引用:

如何在PHP中创建图形

How to create graph in PHP



首先,php是服务器端语言,它用于准备将被发送到的页面客户端浏览器。

JS和HTML是客户端。

基本上有3种方法可以在html页面中制作图表。

- The一些JS代码在客户端操作的画布。

- 服务器端的图片或服务器端的php代码制作的图片。

- SVG图表是在服务器上准备,SVG是一个文件或嵌入在html页面中。

这个网站是一个很好的起点: W3Schools在线网络教程 [ ^ ]

SVG教程 [ ^ ]

PHP 5教程 [ ^ ]


First of all, php is server side language, it is used to prepare page that will be sent to client browser.
JS and html are client side.
There is basically 3 ways to make a graph in an html page.
- The canvas which is manipulated on client side by some JS code.
- A picture which is on server or made by php code on server side.
- A SVG graph which is prepared on server, SVG is either a file or embedded in the html page.
This site is a good starting point: W3Schools Online Web Tutorials[^]
SVG Tutorial[^]
PHP 5 Tutorial[^]


PHP在服务器上运行。 Javascript在客户端上运行,正是您需要使用的,除非您决定在后端生成静态位图然后提供它。我从来没用过PHP,但是,我想它只能通过COM对象来做?
PHP runs on the server. Javascript runs on the client and is precisely what you need to use, unless you're determined to generate a static bitmap on the back end and then serve it. I'v never used PHP, but, I imagine it could only do that via a COM object?


这篇关于如何在PHP中创建图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆