【问题标题】:link inside array or different link for window.location数组内的链接或 window.location 的不同链接
【发布时间】:2019-10-10 00:36:29
【问题描述】:

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

}

【问题讨论】:

    标签: javascript php arrays canvas


    【解决方案1】:

    在您的数组中添加一个函数。您的数据点应如下所示。

    label: // your label
    y: // your y
    click: function(e){ window.location = "www.google.com"}
    

    Check this

    【讨论】:

      猜你喜欢
      • 2017-05-01
      • 1970-01-01
      • 2012-07-20
      • 1970-01-01
      • 2022-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多