drb88830 2013-01-13 16:22
浏览 23

如何将PHP Array中的值绘制成Jqplot?

I am new to PHP, javascript and Jqplot. I am making a website where in PHP lets say array1 outputs

Array ( [0] => 0.0024 [1] => 0.0024 [2] => 0.0024 [3] => 0.0024 [4] => 0.00098765432098765 [5] => 0.00098765432098765 [6] => 0.00098765432098765 [7] => 0.001953125 [8] => 0.001953125 [9] => 1 [10] => 1 [11] => 1 [12] => 0.2 [13] => 0.2 [14] => 0.2 [15] => 0.2 [16] => 0.25 [17] => 2 ) 

array 2 outputs

Array ( [0] => 2013-01-13 14:13:05 [1] => 2013-01-13 14:14:56 [2] => 2013-01-13 14:15:05 [3] => 2013-01-13 14:15:13 [4] => 2013-01-13 14:16:48 [5] => 2013-01-13 14:17:20 [6] => 2013-01-13 14:17:56 [7] => 2013-01-13 14:25:06 [8] => 2013-01-13 14:27:28 [9] => 2013-01-13 14:29:41 [10] => 2013-01-13 14:30:36 [11] => 2013-01-13 14:30:53 [12] => 2013-01-13 14:35:37 [13] => 2013-01-13 14:39:52 [14] => 2013-01-13 14:48:30 [15] => 2013-01-13 14:49:40 [16] => 2013-01-13 14:51:23 [17] => 2013-01-13 14:55:05 )

how to plot this data in jqplot?

I would be gratitude for any help. Thanks

  • 写回答

3条回答 默认 最新

  • dounieliang4712 2013-01-13 16:42
    关注

    I'm assuming that you want array1 to be the y-axis, and array2 to be the x-axis. Just output javascript lines in a PHP loop and it should do the trick.

    <script type="text/javascript">
        var lines = [];
    
    <? for ($i=0; $i<count($array1); $i++) { ?>
        lines[<?=$i?>] = ['<?=$array2[$i]?>', <?=$array1[$i]?>];
    <? } ?>
    
        // The array 'lines' will be plotted into 'chart1' when the document loads
        $(document).ready(function(){
            var plot1 = $.jqplot ('chart1', [ lines ]);
        });
    
    </script>
    
    <!-- This is the div where the graph will be displayed -->
    <div id="chart1" style="height:300px; width:500px;"></div>
    

    Plot the above lines array, and you should get what you are desiring.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度