PHP-based ultra-cool HTML5 interactive chart _ PHP Tutorial

Source: Internet
Author: User
PHP-based ultra-cool HTML5 interactive charts. PHP-based ultra-cool HTML5 interactive charts use PHP to implement professional-level Web-based charts without in-depth HTML5 and JavaScript knowledge. Introduction recently, I need to quickly develop PHP-based ultra-cool HTML5 interactive charts from a group of PHP Data groups

Use PHP to implement professional-level Web-based charts without in-depth HTML5 and JavaScript knowledge.

Introduction

Recently, I need to quickly create charts from a group of PHP Data groups. The required charts must be interactive, user-friendly, and downloadable. After evaluating some PHP chart solutions, including phpChart, pChart, and Highcharts, I decided to use phpChart as my preferred tool.

Background

As a major backend programmer, I don't have much time to study using JavaScript to see charts online within 24 hours.) I don't have any advanced front-end coding knowledge. Basically, I want PHP developers who have almost no front-end programming experience to quickly develop exquisite charts.

I tried pChart, a popular PHP chart Library. The generated chart looks pretty good. although it can be downloaded, it is still a static image. Highcharts seems to be the best choice. A chart looks amazing, it is animated, and has many custom options, but it is also very complicated and requires a lot of JavaScript knowledge. Highcharts is neither designed for PHP nor free for business purposes.

Basic elements of phpChart

What I like most about phpChart is that it allows people to start with simple and minimal code.

PhpChart Lite version can be downloaded from http: // phpchArt.org/downLoads /. Download the file and decompress it to the root directory of the website.

Set conf. php

The first thing we need to do is set variables.SCRIPTPATHTo the PhpChart class library in the conf. php file. This variable represents the relative or absolute URL of the phpChart library on your Web server.

 
  1. define('SCRIPTPATH','/phpChart/');

Create the simplest chart

 
  1. Include the PHP header file conf. php:
  2. Require_once ("../conf. php ");

Call constructorC_PhpChartXAnd call the draw () function.

 
  1. $pc=new C_PhpChartX(array(array(123, 34, 51, 22, 3)), ‘simplest_graph’);
  2. $pc->draw();

This is the code you need. The following figure shows the rendered output.

This is what I call the minimum number of codes. When you have a team of programmers to work, it doesn't make sense to study the basics. One thing that any programmer wants to do as soon as possible is to study complex documents from a new set of libraries or tools.

By the way, the name of the second parameter in the constructor should be unique for your chart. I typed "simplest_graph" or any non-space string. It must be a unique value so that you can have multiple charts on a page.

Add title

You should add titles for your charts so that users can know what they are watching.

 
  1. $pc->set_title(array('text'=>’My Simplest Graph'));

Add an animation

One thing pChart cannot do is animation. In phpChart, animations can be used simply by calling set_animate and passing the true value.

 
  1. $pc->set_animate(true);

That's it. At this time, your chart should already have titles and animations. The complete code is as follows:

 
  1. $pc = new C_PhpChartX(array(array(123, 34, 51, 22, 3)),'simplest_graph');
  2. $pc->set_animate(true);
  3. $pc->set_title(array('text'=>'My Simplest Graph'));
  4. $pc->draw();

Code essence

If you view the source in the browser, you will find that phpChart automatically contains many JavaScript and CSS files, including jquery. js, jquery-ui, and jqplot.js、jquery-ui.css. Although the chart is rendered in the browser using the client's JavaScript, all the code at the front end is PHP.

The reason for popularity is that JavaScript is no longer needed for me, a PHP developer, because phpChart will automatically process it for me. The following is all the JavaScript code generated when you view the source code-the result of the previous four lines of PHP code.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.