求一利用php快速生成柱状图的函数,现以完成一个简易函数比较慢。
求一利用php快速生成柱状图的函数,现以完成一个简易函数比较慢。
由于初学,仅会操控CSS生成个简易的柱状图,但我的函数在数据大于25000条的时候超级慢,1万多一点的时候生成图的时间是10多秒。这速度太慢了,求大侠优化。
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><html>
<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>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1101">
<img src="https://img.php.cn/upload/ai_manual/001/503/042/68b6c6af75d71275.png" alt="腾讯智影-AI数字人">
</a>
<div class="aritcle_card_info">
<a href="/ai/1101">腾讯智影-AI数字人</a>
<p>基于AI数字人能力,实现7*24小时AI数字人直播带货,低成本实现直播业务快速增增,全天智能在线直播</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="腾讯智影-AI数字人">
<span>73</span>
</div>
</div>
<a href="/ai/1101" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="腾讯智影-AI数字人">
</a>
</div>
<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 '</table>';
}
$end_time = microtime(true);
$end_time *= 1000 * 1000;
echo "Total time used : " . ($end_time - $beg_time) . "ms" . PHP_EOL;
?>
</html>
$s_time = microtime(true); $d = range(1, 33); $r = array(); for($i=0; $i<font color="#e78608">------解决方案--------------------</font><br>建议楼主看看:ChartDirector软件,现在有破解的,很好用 <div class="clear"></div>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号