JS statistical report column chart, line chart generation

Source: Internet
Author: User

 

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> new document </title>
<Meta name = "generator" content = "editplus">
<Meta name = "author" content = "">
<Meta name = "keywords" content = "">
<Meta name = "Description" content = "">
</Head>

// Add an image storage path
<Base href = "http://www.sharejs.com/code/image/stat/"> </base>
<Style>
V \: * {behavior: URL (# default # VML); position: absolute ;}
Div, TD {font-size: 12px ;}
. Gra {background-color: # cedbff; font-size: 1px; border-bottom: #000000 1px solid ;}
. GRA2 {background-color: #003399; font-size: 1px; border-bottom: #000000 1px solid ;}
</Style>
<SCRIPT>
/*************************************** ***************
* Statistical Graph Generation share JavaScript (http://www.ShareJS.com)
* Use this scriptProgram, Please keep this statement
* To get this script and more javascript programs, visit the http://www.ShareJS.com
**************************************** **************/

VaR d = new array (); // array of statistics
VaR d_ip_max = 0; // maximum number of IP addresses
VaR d_pv_max = 0; // maximum number of PVS
VaR d_ip_all = 0; // total number of IP addresses
VaR d_pv_all = 0; // total PV count
VaR title_all = ""; // Statistical Chart title
VaR title_ip = ""; // IP data title
VaR title_pv = ""; // PV data title
VaR B _w = 0; // column width
VaR B _s_w = 0; // bar chart Interval
VaR base_x; // start coordinate X (used to draw a line chart)
VaR base_y; // start coordinate Y (used to draw a line chart)
Function init_data (v) // initialize data
{
D = new array ();
D_ip_max = 0;
D_pv_max = 0;
D_ip_all = 0;
D_pv_all = 0;
VaR di = V. Split (";");
VaR di0, di1, di2;
D [0] = di [0]. Split (",");
Title_all = d [0] [0];
Title_ip = d [0] [1];
Title_pv = d [0] [2];
B _w = math. Floor (d [0] [3]);
B _s_w = math. Floor (d [0] [4]);
For (VAR I = 1; I <Di. length; I ++)
{
D [I] = di [I]. Split (",");
Di0 = math. Floor (d [I] [0]);
Di1 = math. Floor (d [I] [1]);
Di2 = math. Floor (d [I] [2]);
D_ip_all + = di1;
D_pv_all + = di2;
D_ip_max = d_ip_max> di1? D_ip_max: di1;
D_pv_max = d_pv_max> di2? D_pv_max: di2;
}
}
Function draw_bar (SA) // draw a bar chart
{
VaR sa_div = Document. getelementsbyname ("sa") [SA];
VaR v = sa_div.data;
Init_data (v );
VaR B _d1 = "";
VaR B _d2 = "";
VaR Title = "";
VaR B = '<Div align = "center">' + title_all + '(Bar Chart) <a href = "javascript: draw_line (' + SA + ') ">-> switch to the line chart </a> </div> <Table border =" 0 "cellpadding =" 0 "cellspacing =" 0 "align =" center "> <tr> <TD valign = "TOP" rowspan = "2"> <p align = "right" style = "line-height: 12px; margin-Right: 2 "> ';
For (VAR I = 1; I <D. length; I ++)
{
Title = ''+ title_pv + ':' + d [I] [2] +'' + math. floor (d [I] [2]/d_pv_all * 1000)/10 + '% \ n' + title_ip + ': '+ d [I] [1] + ''+ math. floor (d [I] [1]/d_ip_all * 1000)/10 + '% ';
B _d1 + = '<TD align = "center" valign = "bottom" width = "' + (B _w + B _s_w) + '"background =" tu_back.gif "Title ="' + title + '"> <Div class =" GRA2 "style =" width:' + B _w + '; height: '+ d [I] [2]/d_pv_max * 100 +' "> <Div class =" Gra "style =" width: '+ B _w +'; Border: 0px; height: '+ (d [I] [2]-d [I] [1])/d_pv_max) * 100 + '"> </div> </TD> ';
B _d2 + = '<TD width =' + (B _w + B _s_w) + 'title = "'+ title +'" id = "X _ '+ SA +' _ '+ I +'"> '+ d [I] [0] +' </TD> ';
}
VaR d_per = d_pv_max % 4 = 0? D_pv_max/4: Math. Floor (d_pv_max/4 + 1 );
For (VAR I = 4; I> 0; I --) B + = d_per * I + '<br> ';
B + = '0 </P> </TD> ';
B + = '<TD width = "10" valign = "TOP"> </TD> ';
B + = B _d1;
B + = '<TD width = "10" valign = "TOP"> </TD> </tr> <tr height = "20" align = "center" style = "letter-Spacing: -2; font-family: Arial; font-size: 12px "> <TD> </TD> ';
B + = B _d2;
B + = '<TD> </tr> </table> <Div align = "center"> <SPAN class = "GRA2" style = "height: 10px; width: '+ B _w +'; Border: #000000 1px solid; "> </span> & nbsp; '+ title_ip +'' + d_ip_all +' & nbsp; & nbsp; <SPAN class = "Gra" style = "height: 10; width: '+ B _w +'; Border: #000000 1px solid; "> </span> & nbsp; '+ title_pv +'' + d_pv_all +' </div> ';
Sa_div.innerhtml = B;
}
Function draw_line (SA) // draw a line chart
{
VaR sa_div = Document. getelementsbyname ("sa") [SA];
VaR v = sa_div.data;
Init_data (v );
VaR l_d1 = "";
VaR l_d2 = "";
VaR Title = "";
VaR l_x = '';
VaR l_y = '';
VaR E = Document. getelementsbyname ("X _" + SA + "_ 1") [0];
VaR T = E. offsettop;
VaR L = E. offsetleft;
While (E = E. offsetparent)
{
T + = E. offsettop;
L + = E. offsetleft;
}
E = Document. getelementsbyname ("X _" + SA + "_" + (D. Length-1) [0];
VaR t2 = E. offsettop;
VaR L2 = E. offsetleft;
While (E = E. offsetparent)
{
T2 + = E. offsettop;
L2 + = E. offsetleft;
}
VaR W = (l2-l)/(D. Length-2) * 3/4;
Base_x = L * 3/4-3/2 * W;
Base_y = T * 3/4;
VaR L = '<Div align = "center">' + title_all + '(line chart) <a href = "javascript: draw_bar (' + SA + ') ">-> switch to the bar chart </a> </div> <Table border =" 0 "cellpadding =" 0 "cellspacing =" 0 "align =" center "> <tr> <TD valign = "TOP" rowspan = "2"> <p align = "right" style = "line-height: 12px; margin-Right: 2 "> ';
For (VAR I = 1; I <D. length; I ++)
{
Title = ''+ title_pv + ':' + d [I] [2] +'' + math. floor (d [I] [2]/d_pv_all * 1000)/10 + '% \ n' + title_ip + ': '+ d [I] [1] + ''+ math. floor (d [I] [1]/d_ip_all * 1000)/10 + '% ';
L_d1 + = '<TD align = "center" valign = "bottom" width = "' + (B _w + B _s_w) + '"background =" tu_back.gif "Title ="' + title + '"> </TD> ';
L_d2 + = '<TD width =' + (B _w + B _s_w) + 'title = "'+ title +'" id = "X _ '+ SA +' _ '+ I +'"> '+ d [I] [0] +' </TD> ';
From_x = base_x + I * W;
To_x = base_x + (I + 1) X W;
If (I> 1)
{
From_y = base_y-d [I-1] [2]/d_pv_max * 75;
To_y = base_y-d [I] [2]/d_pv_max * 75;
L_x + = '<v: Line strokecolor = "red" style = "Z-INDEX: 100; left: 0; top: 0" from = "' + from_x + 'pt, '+ from_y + 'pt "to ="' + to_x + 'pt, '+ to_y + 'pt "strokecolor =" black "strokeweight =" 1px "/> ';
From_y = base_y-d [I-1] [1]/d_pv_max * 75;
To_y = base_y-d [I] [1]/d_pv_max * 75;
L_x + = '<v: Line strokecolor = "green" style = "Z-INDEX: 100; left: 0; top: 0" from = "' + from_x + 'pt, '+ from_y + 'pt "to ="' + to_x + 'pt, '+ to_y + 'pt "strokecolor =" black "strokeweight =" 1px "/> ';
}
L_y + = '<v: Line strokecolor = "# eeeeee" style = "Z-INDEX: 10; left: 0; top: 0" from = "' + (from_x + W) + 'pt, '+ base_y + 'pt "to ="' + (from_x + W) + 'pt, '+ (base_y-75) + 'pt "strokecolor =" black "strokeweight =" 1px "/> ';
}
VaR d_per = d_pv_max % 4 = 0? D_pv_max/4: Math. Floor (d_pv_max/4 + 1 );
For (VAR I = 4; I> 0; I --) L + = d_per * I + '<br> ';
L + = '0 </P> </TD> ';
L + = '<TD width = "10" valign = "TOP"> </TD> ';
L + = l_d1;
L + = '<TD width = "10" valign = "TOP"> </TD> </tr> <tr height = "20" align = "center" style = "letter-Spacing: -2; font-family: Arial; font-size: 12px "> <TD> </TD> ';
L + = l_d2;
L + = '<TD> </tr> </table> <Div align = "center"> <span style = "font-size: 1px; background-color: green; Height: 2px; width: '+ B _w +'; Border: #000000 1px solid; "> </span> & nbsp; '+ title_ip + ''+ d_ip_all +' & nbsp; <span style =" font-size: 1px; Background-color: red; Height: 2; width: '+ B _w +'; Border: #000000 1px solid; "> </span> & nbsp; '+ title_pv +'' + d_pv_all +' </div> ';
Sa_div.innerhtml = L + l_x + l_y;
}
Function draw_pic () // draw a Statistical Chart
{
VaR sa_obj = Document. getelementsbyname ("sa ");
For (VAR I = 0; I <sa_obj.length; I ++) draw_bar (I );
}
Window. onload = function () {draw_pic ();}
/*
Document. onmouseover = function () {getxy ();}
Function getxy ()
{
Window. Status = (event. clientx + "," + event. clienty );
}
*/
</SCRIPT>

<Body>
<Div id = "sa" Data = "Access statistics for this week, access IP address, access traffic, 50,455; Sunday, 67,478; Monday, 60,531; Tuesday,; wedday,; Thursday, 59,310; Friday, 57,329; Saturday, "> </div>
<Br>
<Div id = "sa" Data = "Access statistics for the last 7 days: access IP address, access traffic, 33,320; Saturday, 50,455; Sunday, 67,478; Monday,; Tuesday; wednesday, 60,531; Thursday, 59,310; Friday, 57,329 "> </div>
<Br>
<Div id = "sa" Data = "time period Access statistics, IP, PV, 15, 10;, 22;, 19, 32;, 32;, 11, 20;, 42;, 32, 42;, 95;, 57, 75;, 55;, 56, 56;, 22, 25; 15,1, 2; 16,2, 2; 17,7, 15; 18,21, 55; 19,5, 56; 20,23, 56;, 87;, 52, 87 "> </div>

</Body>
</Html>

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.