javascript - 数组内的链接或 window.location 的不同链接

标签 javascript php arrays canvas

我正在使用这个金字塔图。 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"}

Check this

关于javascript - 数组内的链接或 window.location 的不同链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58313920/

相关文章:

javascript - VueJS : Obtaining dynamic component information in method run via v-bind

javascript - jQuery:带有单引号的 td 内容在传递给模态时被 chop

php - 从表#1 获取最新 ID 以确定表#2 的新 ID

php - MySQLi - 从多个表中查询选择的更好方法

arrays - 多个图像意味着 dask.delayed 与 dask.array

javascript - 集成 Owl Carousel +easyzoom

javascript - JS - 将对象数组传递到新窗口

php - 在 PHPUnit 中使用 Spy 对象?

python - 仅使用 32GB 内存分析 80GB 文件中的庞大数据集

c - 寻找数组中最大的子列表?