假设我有以下PHP函数代码:
function.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个按钮,订购红色和订购蓝色,当我点击按钮顺序红色它将排序红色,然后点击按钮蓝色它将排序蓝色Please see this但是当我鼠标悬停在条形图上,我需要显示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
.................................................................................
.................................................................................
.................................................................................
我找不到解决方案,任何人都知道请求帮助我,谢谢。
答案 0 :(得分:1)
将工具提示格式化程序更改为:
this.series.name +': '+ this.y +' ('+ Math.round(this.percentage * 10) +'%)';