Php + highchats generate a dynamic Statistical Chart

Source: Internet
Author: User

Copy codeThe Code is as follows:
Series :[{
Type: 'pie ',
Name: 'browser share ',
Data :[
['Firefox, 45.0],
['Ie', 26.8],
{
Name: 'chromi ',
Y: 12.8,
Sliced: true,
Selected: true
},
['Safari, 8.5],
['Opera, 6.2],
['Others, 0.7]
]
}]

Mainly refer to this section:

Copy codeThe Code is as follows:
{
Name: 'chromi ',
Y: 12.8,
Sliced: true,
Selected: true
}

Copy codeThe Code is as follows:
<! Doctype html>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> FusionCharts </title>
<Script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"> </script>
<Script type = "text/javascript">
$ (Function (){
Var ds = [{"name": "\ u4e0a \ u6d77", "y": 28.2 },{ "name": "\ u5317 \ u4eac", "y ": 48.2 },{ "name": "\ u5e7f \ u4e1c", "y": 18.2}];
// In fact, you only need to display the result in json format, such as chrome.
// Radialize the colors
Highcharts. getOptions (). colors = Highcharts. map (Highcharts. getOptions (). colors, function (color ){
Return {
RadialGradient: {cx: 0.5, cy: 0.3, r: 0.7 },
Stops :[
[0, color],
[1, Highcharts. Color (color). brighten (-0.3). get ('rgb ')] // darken
]
};
});
// Build the chart
$ ('# Iner'). highcharts ({
Chart :{
PlotBackgroundColor: null,
PlotBorderWidth: null,
PlotShadow: false
},
Title :{
Text: 'browser market shares at a specific website, 100'
},
Tooltip :{
PointFormat: '{series. name }:< B> {point. percentage:. 1f }%</B>'
},
PlotOptions :{
Pie :{
AllowPointSelect: true,
Cursor: 'pointer ',
DataLabels :{
Enabled: true,
Color: '#000000 ',
ConnectorColor: '#000000 ',
Formatter: function (){
Return '<B>' + this. point. name + '</B>:' + this. percentage + '% ';
}
}
}
},
Series :[{
Type: 'pie ',
Name: 'browser share ',
Data: ds,
}]
});
});
</Script>
</Head>
<Body>
<Script src = "js/hc. js"> </script>
<Script src = "js/modules/exporting. js"> </script>
<Div id = "container" style = "min-width: 310px; height: 400px; margin: 0 auto"> </div>
<? Php
Area ();
/**
* Region Interface
* Name
* Y Data Value
*
*/
Function area ()
{
$ B = array (
Array ('name' => 'shanghai', 'y' => 28.2 ),
Array ('name' => 'beijing', 'y' => 48.2 ),
Array ('name' => 'guangdong ', 'y' => 18.2 ),
);
$ Data = json_encode ($ B );
Echo ($ data );
}
?>
</Body>
</Html>

Below is the json data output by php for js:

Copy codeThe Code is as follows:
<? Php
$ Strs = @ file ("/proc/net/dev ");
For ($ I = 2; $ I <count ($ strs); $ I ++)
{
Preg_match_all ("/([^ \ s] +): [\ s] {0,} (\ d +) \ s + (\ d +) \ s + (\ d +) \ s + (\ d + )/", $ strs [$ I], $ info );
/* $ NetInput [$ I] = formatsize ($ info [2] [0]);
$ NetOut [$ I] = formatsize ($ info [10] [0]);
*/
$ Tmo = round ($ info [2] [0]/1024/1024, 5 );
$ Tmo 2 = round ($ tmo/1024, 5 );
$ NetInput [$ I] = $ tmo2;
$ Tmp = round ($ info [10] [0]/1024/1024, 5 );
$ Tmp2 = round ($ tmp/1024, 5 );
$ NetOut [$ I] = $ tmp2;

}

$ Arr = array ();
If (false! ==( $ Strs = @ file ("/proc/net/dev "))):
For ($ I = 2; $ I <count ($ strs); $ I ++ ):
Preg_match_all ("/([^ \ s] +): [\ s] {0,} (\ d +) \ s + (\ d +) \ s + (\ d +) \ s + (\ d + )/", $ strs [$ I], $ info );
$ Arr [$ I] ["name"] = $ info [1] [0];
$ Arr [$ I] ["data"] [0] = $ NetInput [$ I];
$ Arr [$ I] ["data"] [1] = $ NetOut [$ I];

Endfor;
Endif;
Echo (json_encode ($ arr ));
?>

Output:

Copy codeThe Code is as follows:
{"2": {"name": "lo", "data": [0, 0]}, "3": {"name": "eth0", "data ": [0.40377, 0.00353]}

Js call:

Copy codeThe Code is as follows:
Series :[
<Span style = "white-space: pre"> </span> ds [2], ds [3]
<Span style = "white-space: pre"> </span>]

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.