gpt4 book ai didi

javascript - Highcharts 饼图可以有 url 链接

转载 作者:可可西里 更新时间:2023-10-31 22:54:35 24 4
gpt4 key购买 nike

我在我的应用程序中使用 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";

最佳答案

highcharts 网站上有一个例子显示了类似的东西。您可以使用点/事件/点击功能来触发新的页面加载:

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

http://jsfiddle.net/w5Lx4/

注意,在这个例子中,URL被添加到系列数据中:

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

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

关于javascript - Highcharts 饼图可以有 url 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24465663/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com