我正在使用这个金字塔图。 https://canvasjs.com/php-charts/pyramid-chart/ 数组可以点击吗?例如数组是这样的
$dataPoints = array (
array ("label" => "www.google.com", "y" => 8531),
array ("label" => "www.yahoo.com", "y" => 4550),
array ("label" => "www.facebook.com", "y" => 4395)
)
这是我尝试过的..我点击的每一行都需要有一个不同的链接。但这个 window.location 唯一做的是每次我点击任何位置时它都会转到同一个链接
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
title: {
text: "Order Fulfillment"
},
data: [{
click: function (e) {
window.location = 'https://www.google.com';
},
type: "pyramid",
indexLabel: "{label} - {y}",
yValueFormatString: "#,##0",
dataPoints: <?php echo json_encode($dataPoints, JSON_NUMERIC_CHECK); ?>
}]
});
chart.render();
}
最佳答案
在数组中添加一个函数。您的数据点应该如下所示。
label: // your label
y: // your y
click: function(e){ window.location = "www.google.com"}
关于javascript - 数组内的链接或 window.location 的不同链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58313920/