Archives

Recent Posts

Categories

Blogroll

Graphs of Google and PHP library to work with them

V Last time I promised to tell you about how to create graphics for their resources and do not load server. Rech, of course, goes on the web service Google Chart. This service has quite a long time and today there are many libraries to work with him. But to the service and libraries, we will return, and now discuss the options for the establishment of timetables for the web stranits. Glavnaya problema Na today to draw a schedule using only HTML, you can not. Therefore have to use the bypass varianty. 1) Create an image with the schedule and insert it into stranitsu. 2) Use Flash. On this form, I talked to in Article graphs with their own hands – Open Flash Chart 2. On-the idea, instead of Flash, you can use Silverlight, but I have not videl. Primechanie. Big Shark suggested another flash library to create graphs – amCharts. It is a look. Perhaps you'd enjoy it more than the Open Flash Chart. Rassmotrim details the first option. Figure to the schedule can be static or dinamicheskim. Staticheskie created in advance and when you open the page the visitor just sent emu. Dinamicheskie created byEach time anew. Typically, using the GD library or ImageMagick. More precisely, in most cases, special libraries are used to create graphs (eg, GraPHPite or pChart), who use GD or ImageMagick. Estestvenno, in terms of load on the server, static graphics is much more profitable. But if on the graph to display data that is constantly changing, for example, data on attendance, this option is not podoydet. Ispolzovanie Flash is much more interesting. The schedule is created on the client side, Flash Player. You have to send him the necessary dannye. No and there is a problem. Flash movie, which is used to create graphics quite voluminous. For example, in the library of Open Flash Chart, it takes 264kB. Konechno, the lack of an advantage if you want to place a few tens of graphs on the page. Since total volume of drawings of graphs will be more than the movie, who downloaded the browser, only one raz. No if you need to show only one graph, as it does not properly load the visitor 260 KB instead of 10-20 kb, which would hold a schedule in png format ??. T.e. In this case you need to create graphics dynamically. And while it would be a good idea to avoid disagreement with the hoster on the load on server. Primechanie. This, of course, is a shared hosting. If you have a dedicated server, then your problem with the load will not be interested in hosting V such cases it makes sense to use an outside service. Ie picture schedule will be created are not yours, but stranger serverom. Printsip work Google Chart 1) Your server script receives the data for display on grafike. 2) On the basis of these data formed a special type of URL that points to the server Google (URL starts with http:/ / chart.apis.google.com /is quite broad, but if using GD, you can draw almost anything, the restrictions did prisutstvuyut. 2) You depend on a third-party service. Interesting, by the way, the question that reliably Google Chart or your life? 3) There is a limit to the number of requests – 50 000 per user per day. I do not think that this is a serious limitation for most resursov. Teper most interesting. Creating URL. Pervaya part of the URL postoyannaya. http: / / chart.apis.google.com / chart? Posle Its parameters are in the form name = znachenie. T.k. there are certain restrictions on the length of URL, then the developers propose to use the Google Chart dannyh. Tsel special coding is simple – to minimize the length URL. Estestvenno, encode the data manually, do not like it. Therefore, a heap bibliotek. Primer use one of them I want pokazat. Biblioteka called GphpChart. Sozdadim simple stranichku. ? When creating an object GphpChart need to specify the type of schedule. Used by the reduction in the Google Chart API. Posle indicate that arrays with dots graphics and signatures on osyam. A using get Image String () form a line with tag img. V result is grafik. K Unfortunately, all the libraries with whom I had the case do not support the full capabilities Google Chart. For example, I have not found any that would have supported the creation of graphs type Radar. V such cases, you will have to rely on themselves and write the code handles all fairness, I want to say that it does not slozhno. Samaya complex operation – data encryption. But the documentation is an example JavaScript function which performs this preobrazovanie. I to rewrite it in another language is not difficult. By the way, for PHP is already sdelano. V general, if you want to use graphics on your site, then choose from there chego. Do meeting!