单击饼图时从highcharts调用函数

时间:2014-03-07 11:50:19

标签: php highcharts

当有人点击我使用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";
}

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

1 个答案:

答案 0 :(得分:2)

对切片使用on click事件。

Docs