【问题标题】:Show Information From Database onclick of HighCharts显示来自数据库的信息 onclick 的 HighCharts
【发布时间】: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 eventtooltip.formatter 从 this.point.options.customParam 参考中提取。
  • 我不明白..你能告诉我任何示例代码
  • 你的每个数据点都应该是对象。为此,请在 PHP 中创建点并设置参数(如 x、y、customParam)时使用 array()。

标签: javascript php jquery mysql highcharts


【解决方案1】:

我不太明白你想在点击后显示什么。但是highcharts中有一个点击事件。

链接:http://api.highcharts.com/highcharts#plotOptions.pie.point.events.click

在他们的演示页面上,他们提供了一个示例图:http://www.highcharts.com/demo/line-ajax

以下代码与您相关。将其添加到您的 plotOptions.pie 对象中

point: {
    events: {
        click: function (e) {
            // your code for on click
        }
    }
}

【讨论】:

  • 我想从数据库中获取相应的学生详细信息并将其显示在表格中。当点击每个切片时会发生这种情况
  • 是的,正如我已经说过的,只需将检索数据的逻辑放在 click 函数中即可。您还可以查看显示数据的 highcharts 示例
猜你喜欢
  • 1970-01-01
  • 2018-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-26
  • 1970-01-01
  • 1970-01-01
  • 2021-09-20
相关资源
最近更新 更多