求一利用php快速生成柱状图的函数,现以完成一个简易函数比较慢。
求一利用php快速生成柱状图的函数,现以完成一个简易函数比较慢。
由于初学,仅会操控CSS生成个简易的柱状图,但我的函数在数据大于25000条的时候超级慢,1万多一点的时候生成图的时间是10多秒。这速度太慢了,求大侠优化。
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <style type="text/css"> .chart { font-family: Tahoma; font-size: 12px; border: 1px solid #ccc; width:auto; float: left; margin: 0; padding: .4em .1em; height:auto; } .chart ul { margin:0px; height:auto; text-align: center; display:block; background-repeat: no-repeat; background-position: center bottom; background-attachment: fixed; } .chart li { list-style: none; float: left; width: 35px; height:200px; text-align: center; display:block; background-repeat: no-repeat; background-position: center bottom; background-attachment: fixed; } .b { display: block; width:15px; background-color:#000; margin-right: auto; margin-left: auto; } .a { height:12px; width:35px; background-color:#fff; padding: 0px; } </style> <?php $beg_time = microtime(true); $beg_time *= 1000 * 1000; create_chart2(); function create_chart2() {//x一维数组直接输出图表 //思路先得到一个一维数组,然后统计值的个数,最后排序输出 //echo '<table>'; $returnarray2=array(); $db1=new mysqli('localhost','admin','admin','ssq') ; $sql_query='select l1,l2,l3,l4,l5,l6 from hmk_temp_1 as bb limit 0,1000'; $res1=$db1->query($sql_query); while($row1=mysqli_fetch_array($res1,MYSQLI_NUM)) { $returnarray2=array_merge($returnarray2,$row1); } $array_values=array_count_values($returnarray2); ksort($array_values); //print_r($array_values); $rates=round(200/max($array_values),2); echo '$rates='.$rates; echo '<div class="chart"> <p>一区</p> <ul>'; foreach($array_values as $key=>$value){ echo '<li> <span class="a" style="margin-top:'.(210-$value*$rates).'px;">' .$value.'</span><span class="b" style="height:'.($value*$rates).'px;">'.'</span><span class="a">'.$key.'</span> </li>' ; } echo '</ul> </div> <p style="clear: both"></p>' ; //echo ''; } $end_time = microtime(true); $end_time *= 1000 * 1000; echo "Total time used : " . ($end_time - $beg_time) . "ms" . PHP_EOL; ?>
------解决方案--------------------
先找出瓶颈是在什么地方
有没考虑过使用 pChart?
------解决方案--------------------
Google有一个库提供。楼主可以查一下。
------解决方案--------------------
输出的 Total time used 看似巨大,但由于计量单位有误,就不足信了
microtime(true) 返回的是秒, * 1000 * 1000 后为微秒,你把它当做毫秒,就放大了 1000 倍
代码简单并不代表运行效率就高,看一下这个测试就知道了
- PHP code
$s_time = microtime(true); $d = range(1, 33); $r = array(); for($i=0; $i<font color="#e78608">------解决方案--------------------</font><br>建议楼主看看:ChartDirector软件,现在有破解的,很好用 <div class="clear"> </div>

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.