假设我有如下 PHP 函数代码:
函数.php
function PMTA_CHART($contentID, $chartName, $file, $order) {
$cate = '';
$total = '';
$fail = '';
$chart = array();
$title = "";
$PercentBlue = 0;
$PercentRed = 0;
if (file_exists($file)) {
$files = fopen($file, 'r');
while (!feof($files)) {
$data = explode(";", fgets($files));
if ($title == "") {
$title = $data[0];
}
if (!empty($data[5])) {
$cate = $data[5];
$PercentBlue = ((int)$data[6] - (int)$data[7]);
$PercentRed = (int)$data[7];
if (!empty($order)) {
$PercentBlue = (100 - (int)$data[8]);
$PercentRed = (int)$data[8];
$chart[] = array($PercentBlue, $PercentRed, $cate);
} else {
$PercentBlue = (100 - (int)$data[8]);
$PercentRed = (int)$data[8];
$chart[] = array($PercentRed, $PercentBlue, $cate);
}
}
}
arsort($chart);
$cate = '';
$PercentBlue = 0;
$PercentRed = 0;
if (!empty($order)) {
foreach ($chart as $arr) {
$cate.= ',' . "'$arr[2]'";
$PercentBlue.= ',' . $arr[0];
$PercentRed.= ',' . $arr[1];
}
} else {
foreach ($chart as $arr) {
$cate.= ',' . "'$arr[2]'";
$PercentBlue.= ', ' . $arr[1];
$PercentRed.= ', ' . $arr[0];
}
}
fclose($files);
} else {
echo "No such file";
}
?>
<?php echo $chartName ?> = new Highcharts.Chart({
chart: {
renderTo: '<?php echo $contentID ?>',
type: 'column'
},
title: {
text: '<?php echo $title; ?>'
},
xAxis: {
categories: [<?php echo substr($cate, 1); ?>],
labels: {
rotation: 90,
align: 'left'
}
},
yAxis: {
min: 0,
title: {
text: '% envoi'
}
},
tooltip: {
formatter: function() {
return ''+
this.series.name +': '+ this.y +' ('+ Math.round(this.percentage) +'%)';
}
},
plotOptions: {
column: {
stacking: 'percent'
}
},
series: [{
name: 'Total mail succesful',
data: [<?php echo substr($PercentBlue, 2); ?>]
}, {
name: 'Total mail fail',
data: [<?php echo substr($PercentRed, 2); ?>]
}]
});
pmtaChart.php
<?php
include('include/function.php');
$pmta3_emetteur_file = '../stats_domain_emetteur.affinitead.net.'.date("Y-m-d").'.txt';
$pmta4_emetteur_file = '../stats_domain_emetteur.switchcall.com.'.date("Y-m-d").'.txt';
$pmta5_emetteur_file = '../stats_domain_emetteur.unitead.eu.'.date("Y-m-d").'.txt';
$order = isset($_POST['txt_order_blue'])?$_POST['txt_order_blue']:'';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Chart</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var chart3, chart4, chart5;
$(document).ready(function() {
<?php PMTA_CHART('PMTA3', 'chart3', $pmta3_emetteur_file, $order); ?>
<?php PMTA_CHART('PMTA4', 'chart4', $pmta4_emetteur_file, $order); ?>
<?php PMTA_CHART('PMTA5', 'chart5', $pmta5_emetteur_file, $order); ?>
});
});
</script>
</head>
<body>
<script src="js/highcharts.js"></script>
<script src="js/exporting.js"></script>
<form action="pmtaEmetteur.php" method="post">
<input type="submit" name="txt_order_red" id="txt_order_red" title="Order Red" value="Order Red"/>
<input type="submit" name="txt_order_blue" id="txt_order_blue" title="Order blue" value="Order blue"/>
</form>
<div id="PMTA3" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<div id="PMTA4" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
<div id="PMTA5" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>
</html>
正如您在代码中看到的,我有 2 个按钮,顺序为红色和顺序为蓝色,当我单击按钮顺序红色时,它会排序为红色,然后单击按钮蓝色,它将排序为蓝色请看这个,但是当我将鼠标悬停在条形图上时,我需要显示Total mail successful : 700 (70 %)
,Total mail fail 300(30%)
但在此图表中,它与我需要显示的内容不同Total mail successful : 70(70%)
,并且Total mail fail : 30(30%)
.
笔记:
正如您在我的代码中看到的那样,我从文件中读取的所有数据。这是文件中的示例文本:
2012-12-19-0230;affinitead.net;557469;141107;25.31;boulevard-des-ventes.com;370873;116793;31.49
2012-12-19-0230;affinitead.net;557469;141107;25.31;tendancity.com;53296;13121;24.61
2012-12-19-0230;affinitead.net;557469;141107;25.31;friendcorp.fr;34365;4086;11.89
2012-12-19-0230;affinitead.net;557469;141107;25.31;messengear.fr;32068;1227;3.82
2012-12-19-0230;affinitead.net;557469;141107;25.31;affinimail.com;27415;2231;8.13
2012-12-19-0230;affinitead.net;557469;141107;25.31;diffitalia.com;2;0;0
.................................................................................
.................................................................................
.................................................................................
我找不到解决办法,有知道的请帮帮我,谢谢。