du22399 2019-03-27 00:33
浏览 186

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

I have 2 arrays;

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

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

I want to show them in one line chart. 'Array x' will be my X-Axis and 'Array y' will be my Y-Axis.

Also I combined those 2 arrays in one array,

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

If I can show it in my chart, it's OK too.

I'm a rookie on php, I searched but couldn't find how to do it. All examples are about only one array. Is there anyone help me about it ? Or can I create that chart with HTML ?

I want my graph like this

Thank you !

  • 写回答

1条回答 默认 最新

  • duandi1919 2019-03-27 04:16
    关注

    Yoc can do it with the support of CanvasJS library

    <!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

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)