PHP-在一个折线图中显示两个数组

时间:2019-03-27 00:33:29

标签: php graph charts linechart

我有2个数组;

x = 800,1650,2450,3200,4150,5250,6200,7150,8000

y = 800,850,800,750,950,1100,950,950,850

我想在一个折线图中显示它们。 “数组x”将成为我的X轴,“数组y”将成为我的Y轴。

我也将这两个数组组合成一个数组,

$arrgraph = array_combine($y, $x);

如果我可以在图表中显示它,也可以。

我是php上的新秀,我进行了搜索,但找不到如何做。所有示例仅涉及一个数组。有没有人帮我解决这个问题?还是可以使用HTML创建该图表?

I want my graph like this

谢谢!

1 个答案:

答案 0 :(得分:0)

Yoc可以在CanvasJS库的支持下做到这一点

<!DOCTYPE HTML>
<html>
<head>  
  <script type="text/javascript">
  window.onload = function () {
    var chart = new CanvasJS.Chart("chartContainer",
    {
      title:{
      text: "Multi-Series Line Chart"  
      },
      data: [
      {        
        type: "line", //you can echo php array here as dataPoints variable
        dataPoints: [
        { x: 10, y: 21 },
        { x: 20, y: 25},
        { x: 30, y: 20 },
        { x: 40, y: 25 },
        { x: 50, y: 27 },
        { x: 60, y: 28 },
        { x: 70, y: 28 },
        { x: 80, y: 24 },
        { x: 90, y: 26}
      
        ]
      }
      ]
    });

    chart.render();
  }
  </script>
 <script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script></head>
<body>
  <div id="chartContainer" style="height: 300px; width: 100%;">
  </div>
</body>
</html>

For more details visit Basic Multi-Series Chart