【发布时间】:2016-06-01 06:33:09
【问题描述】:
大家好,
在我的应用程序中,将有一个部分命名为管理面板。管理员可以在其中根据学生个人资料完成情况在高图中查看报告。 下面是示例页面
我的数据库示例
在这里,我的图表解释了 2 名学生完成了 80-100% 的个人资料。此信息取自数据库。同样,我想获取相应的学生信息。当他们单击切片时,我如何获取该学生的详细信息饼图。点击图表将显示80-100%类别的学生的详细信息。类似地,如果他点击绿色,它将显示数据库中40-60%类别的学生的详细信息。如果有人知道解决方案,我该怎么做,请告诉我。 以下是我的代码
Javascript
<div id="stage" style="padding-bottom:80px;" ></div>
var stage = {
chart: {
renderTo: 'stage',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'No. of Applicants by Profile Completion'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.y ;
}
},
credits: {
enabled: false
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
distance: 10,
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.y;
},
},
showInLegend: true
}
},
series: [{
type: 'pie',
name: '',
data: [],
dataLabels: {
color:'black',
distance: -30,
formatter: function () {
return '<b style="font-size:16px;">'+ this.y +'</b> ';
}
}
}]
}
$.getJSON("get_stage_chart.php", function(json) {
stage.series[0].data = json;
chart = new Highcharts.Chart(stage);
});
get_stage_chart.php
<?php
date_default_timezone_set('Asia/Kolkata');
$date = date("Y-m-d");
$time = date("Y-m-d H:i:s");
require "reports.php";
$reports = new reports();
$stages = $reports->stage_report();
$i=0;
foreach ($stages as $stage) {
$name[$i] = $stage['percentage'];
$val[$i] = $stage['users'];
$i++;
}
$jsonData = array();
$i=0;
foreach ($stages as $stage) {
array_push($jsonData,array($name[$i],intval($val[$i])) );
$i++;
}
echo json_encode($jsonData);
exit;
?>
reports.php
<?php
include ("dbConnection.php");
class reports
{
public $link;
function __construct()
{
$dbc = new dbConnection();
$this->link = $dbc->Connect();
return $this->link;
}
public function stage_report()
{
$q = $this->link->prepare('SELECT distinct percentage As percentage,count(percentage) As users from details group by percentage');
$q->execute();
$count = $q->fetchall();
return $count;
}
}
?>
如果有人为我的问题提供解决方案,那将对我非常有帮助。在此先感谢。
【问题讨论】:
-
您可以将该信息保存在每个点的自定义参数中。即 {y: 10, customParam: '您的自定义文本和信息'}。然后在 click event 或 tooltip.formatter 从 this.point.options.customParam 参考中提取。
-
我不明白..你能告诉我任何示例代码
-
你的每个数据点都应该是对象。为此,请在 PHP 中创建点并设置参数(如 x、y、customParam)时使用 array()。
标签: javascript php jquery mysql highcharts