2014-03-07 2 views
0

하이 차트를 사용하여 작성한 파이 차트를 클릭하면 함수를 호출하고 싶습니다.파이 차트를 클릭하면 하이 차트에서 함수 호출

내 파이 차트 코드는 다음과 같습니다

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

관련 문제