Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Highcharts饼图可以有url链接_Javascript_Php_Jquery_Charts_Highcharts - Fatal编程技术网

Javascript Highcharts饼图可以有url链接

Javascript Highcharts饼图可以有url链接,javascript,php,jquery,charts,highcharts,Javascript,Php,Jquery,Charts,Highcharts,我在应用程序中使用Highcharts饼图,饼图的数据是从数据库填充的。我的问题是在填充饼图之后,如果我单击某个区域,它应该呈现给特定的php页面。可能吗 这是我的密码: function open_risk_level_pie() { $chart = new Highchart(); $chart->chart->renderTo = "open_risk_level_pie"; $chart->chart->plotBack

我在应用程序中使用Highcharts饼图,饼图的数据是从数据库填充的。我的问题是在填充饼图之后,如果我单击某个区域,它应该呈现给特定的php页面。可能吗

这是我的密码:

    function open_risk_level_pie()
    {
    $chart = new Highchart();

    $chart->chart->renderTo = "open_risk_level_pie";
    $chart->chart->plotBackgroundColor = null;
    $chart->chart->plotBorderWidth = null;
    $chart->chart->plotShadow = false;
    $chart->title->text = "Risk Level";

    $chart->tooltip->formatter = new HighchartJsExpr("function() {
    return '<b>'+ this.point.name +'</b>: '+ this.point.y; }");

    $chart->plotOptions->pie->allowPointSelect = 1;
    $chart->plotOptions->pie->cursor = "pointer";
    $chart->plotOptions->pie->dataLabels->enabled = false;
    $chart->plotOptions->pie->showInLegend = 1;
    $chart->plotOptions->pie->colors = array('red', 'orange', 'yellow', 'black');
    $chart->credits->enabled = false;

    // Open the database connection
    $db = db_open();

// Get the risk levels
$stmt = $db->prepare("SELECT * from `risk_levels`");
$stmt->execute();
$array = $stmt->fetchAll();
$high = $array[0][0];
$medium = $array[1][0];
$low = $array[2][0];

    // Query the database
    $stmt = $db->prepare("select a.calculated_risk, COUNT(*) AS num, CASE WHEN a.calculated_risk >= " . $high . " THEN 'High' WHEN a.calculated_risk < " . $high . " AND a.calculated_risk >= " . $medium . " THEN 'Medium' WHEN a.calculated_risk < " . $medium . " AND a.calculated_risk >= " . $low . " THEN 'Low' WHEN a.calculated_risk < " . $low . " AND a.calculated_risk >= 0 THEN 'Insignificant' END AS level from `risk_scoring` a JOIN `risks` b ON a.id = b.id WHERE b.status != \"Closed\" GROUP BY level ORDER BY a.calculated_risk DESC");
    $stmt->execute();

    // Store the list in the array
    $array = $stmt->fetchAll();

    // Close the database connection
    db_close($db);

    // If the array is empty
    if (empty($array))
    {
            $data[] = array("No Data Available", 0);
    }
    // Otherwise
    else
    {
            // Create the data array
            foreach ($array as $row)
            {
                    $data[] = array($row['level'], (int)$row['num']);
            }

            $chart->series[] = array('type' => "pie",
                    'name' => "Level",
                    'data' => $data);
    }

echo "<div id=\"open_risk_level_pie\"></div>\n";
echo "<script type=\"text/javascript\">";
echo $chart->render("open_risk_level_pie");
echo "</script>\n";
功能打开\u风险\u级别\u饼()
{
$chart=新的Highchart();
$chart->chart->renderTo=“打开风险等级饼”;
$chart->chart->plotBackgroundColor=null;
$chart->chart->PLOTBORDERWITH=null;
$chart->chart->plotShadow=false;
$chart->title->text=“风险等级”;
$chart->tooltip->formatter=new HighchartJsExpr(“函数()){
返回“+this.point.name+”:“+this.point.y;}”);
$chart->plotOptions->pie->allowPointSelect=1;
$chart->plotOptions->pie->cursor=“pointer”;
$chart->plotOptions->pie->dataLabels->enabled=false;
$chart->plotOptions->pie->showInLegend=1;
$chart->plotOptions->pie->colors=array('red'、'orange'、'yellow'、'black');
$chart->credits->enabled=false;
//打开数据库连接
$db=db_open();
//获取风险级别
$stmt=$db->prepare(“从“风险水平”中选择*”;
$stmt->execute();
$array=$stmt->fetchAll();
$high=$array[0][0];
$medium=$array[1][0];
$low=$array[2][0];
//查询数据库
$stmt=$db->prepare(“选择a.computed_risk,COUNT(*)作为num,当a.computed_risk>=”$high.。然后当a.computed_risk<“$high.”时为“high”。当a.computed_risk<“$medium.”时为“medium”。当a.computed_risk>=”$low.“low”时为“low”。当a.computed_risk<“$low.”时为“low”。“和a.计算的风险>=0,然后‘不重要’结束为a.id上的‘风险评分’a加入‘风险’b=b.id,其中b.状态!=\“已关闭”按a.计算的风险描述逐级排序”);
$stmt->execute();
//将列表存储在数组中
$array=$stmt->fetchAll();
//关闭数据库连接
db_close($db);
//如果数组为空
if(空($array))
{
$data[]=数组(“无可用数据”,0);
}
//否则
其他的
{
//创建数据数组
foreach($array作为$row)
{
$data[]=数组($row['level'],(int)$row['num']);
}
$chart->series[]=array('type'=>“pie”,
“名称”=>“级别”,
“数据”=>$data);
}
回音“\n”;
回声“;
echo$chart->render(“开放式风险等级饼状图”);
回音“\n”;

}

highcharts网站上有一个exmaple,显示了类似的内容。您可以使用point/events/click功能触发新页面加载:

 plotOptions: {
        series: {
            cursor: 'pointer',
            point: {
                events: {
                    click: function() {
                        location.href = this.options.url;
                    }
                }
            }
        }
    },

注意,在本例中,URL被添加到序列数据中:

 data: [{
            y: 29.9,
            url: 'http://bing.com/search?q=foo'
        }, {

您可以将其替换为基于点y值生成URL。

您可以捕捉点/系列或图表,然后运行任何函数。我使用的是window.open(“);工作正常。。但是当谈到基于sass的东西如何为不同的实例提供URL时,我不明白你在问什么。工作正常,但是如何在这个链接的新选项卡中打开