首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用php绘制google散布图?

如何使用php绘制google散布图?
EN

Stack Overflow用户
提问于 2011-04-05 08:20:13
回答 1查看 1.5K关注 0票数 2

我一直试图用google在散点图上绘制这些图。但似乎不起作用。

S.No:1价格:0.632卷:10.26 S.No:2价格:0.631卷:10 S.No:3价格:0.631卷:20 S.No:4价格:0.631卷:4.65卷

我有上百个这样的条目,它代表了比特币的价值。

我想把它画成垂直轴和序列号上的价格。在水平轴。体积将定义圆的直径。

代码语言:javascript
运行
复制
<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
        data.addColumn('number', 'Transactions');
        data.addColumn('number', 'Price');
        data.addRows(6);
        data.setValue(1, 0.632, 10.26);
        data.setValue(2, 0.631, 10);
        data.setValue(3,0.631, 20);
        data.setValue(4, 0.631, 4.65);



        var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
        chart.draw(data, {width: 400, height: 240,
                          title: 'Bitcoins Transaction Prices',
                          hAxis: {title: 'Transactions', minValue: 1, maxValue: 100},
                          vAxis: {title: 'Price', minValue: 0, maxValue: 5},
                          legend: 'none'
                         });
      }
    </script>
  </head>

  <body>
    <div id="chart_div"></div>
  </body>
</html>

这会给我返回一个空白页。可能出什么事了?我以为例。下面给出了我得到这些值的php代码。

代码语言:javascript
运行
复制
<?php
//get the unix time stamp of day 30 days back from today
$last_thirty = strtotime('-30 days'); 
//get the unix time stamp of day 1 month back from today
$last_month = strtotime("-1 month"); 
//get the data using bitcoinchart http api
$json = file_get_contents('http://bitcoincharts.com/t/lasttrades.json?limit=10&since=' . $last_month);
//decode json to php array
$data = json_decode($json);
$no = 1;
//loop through it
foreach ($data as $item) {
    $sn =  "S.No:".$no . "";
    $price = "Price:{$item->price}";
    $volume = "Volume:{$item->volume}";
    $no++;
    echo $sn . "<br/>";
    echo $price . "<br/>";
    echo $volume . "<br/>";

} ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-29 05:25:40

完整的文档可以在这里找到。charts.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5549082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档