2014-03-07 14 views
0

当有人点击我使用Highchart构建的饼图时,我想调用一个函数。在点击饼图时从高图调用函数

我的饼图代码:

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

    $chart->chart->renderTo = "open_risk_level_pie"; 
    $chart->chart->plotBackgroundColor = lightblue; 
    $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; 

    $array = //some db access code 
$high = $array[0][0]; 
$medium = $array[1][0]; 
$low = $array[2][0]; 

    // 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"; 
} 

现在我想调用一个函数只要有人点击饼图上。我搜查了很多,但无法找到。有些网站提到使用“格式化程序”,但我没有使用它。如果格式化程序是我的问题的解决方案,请给我上述代码的步骤。

回答

2

对切片使用单击事件。

Docs

+0

这个答案的质量很差,但是非常正确。 –

+0

谢谢,请批准我的答案。我赶时间赶上公共汽车,这是我能想到的唯一的事情:) –

+0

@PawełFus你可以请你详细说明你的答案,我不知道如何使用点击事件,我尝试了很多但它不起作用。 谢谢 – santu47