首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Google发出AJAX请求时,生成高级图表会出现在infowindow窗口

问使用Google发出AJAX请求时,生成高级图表会出现在infowindow窗口
EN

Stack Overflow用户
提问于 2014-05-14 13:57:16
回答 1查看 522关注 0票数 0

使用这个演示这里,我从我的mySQL表创建了一个映射。

现在我想把一个HighChart放在in中,但是我不能让它出现,所以我想要从与标记信息相同的表中提取图表数据。

如有任何建议,将不胜感激。

页面在这里,http://map.itp.ca/,我要列出城市失业率与全国平均水平的对比。

代码语言:javascript
复制
<!DOCTYPE html>
 <html>
<head>
<title>Employment</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Styles -->
<!-- Bootstrap CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="http://map.itp.ca/css/style.css" rel="stylesheet">
代码语言:javascript
复制
<script type="text/javascript">
 $(function () {
    $('#chart_joblessness').highcharts({
        chart: {
            type: 'bar',
            backgroundColor:'rgba(255, 255, 255, 0.1)'
        },
        title: {
            text: ''
        },
        xAxis: {
            categories: ['Total Workforce', 'Youth', 'Women', 'Imigrants']
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Percentage'
            }
        },
        legend: {
            reversed: true
        },
       plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
            series: [{
            name: 'ICT Jobs',
            data: [2.7, 4.4, 3.1, 2.8]
        }, {
            name: 'Canada',
            data: [7, 13, 6, 7.9]
         }]
    });
});
 </script>  

<script src="http://map.itp.ca/charts/js/highcharts.js"></script>
<script src="http://map.itp.ca/charts/js/modules/exporting.js"></script>    

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?   sensor=true"></script>
<script type="text/javascript">
//<![CDATA[

var customIcons = {
  LargeUrban: {
    icon: 'img/chart-pin.png'
  },
  Medium: {
    icon: 'img/chart-pin.png'
  },
  Small: {
    icon: 'img/chart-pin.png'
  }
};


function load() {
  var map = new google.maps.Map(document.getElementById("map"), {
    center: new google.maps.LatLng(47.899754, -90.137494),
    zoom: 5,
    mapTypeId: 'roadmap'
 });




  var infoWindow = new google.maps.InfoWindow;

  // Change this depending on the name of your PHP file
  downloadUrl("phpsqlajax_genxml2.php", function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
      var name = markers[i].getAttribute("city");
      var type = markers[i].getAttribute("type");
      var population = markers[i].getAttribute("population");
      var point = new google.maps.LatLng(
          parseFloat(markers[i].getAttribute("lat")),
          parseFloat(markers[i].getAttribute("lng")));
      var html = '<div id="content">'+
        '<h2 id="firstHeading" class="firstHeading">' + name + '</h2>'+
        '<div id="bodyContent">'+
        '<p><b>ICT Employment</b>, ' + population + ' </p>' +
        '<div id="chart_joblessness" style="z-index:9999; min-width: 500px; max-width: 600px; height: 230px;"></div>'+
        '<p><a href="#" class="btn btn-primary" role="button">Additional City Data</a>  '+
                    '<a href="#" class="btn btn-primary" role="button">Another Button</a></p>'+
                    '</div>';

      var icon = customIcons[type] || {};
      var marker = new google.maps.Marker({
        map: map,
        position: point,
        icon: icon.icon
      });
      bindInfoWindow(marker, map, infoWindow, html);
    }
  });
}

function bindInfoWindow(marker, map, infoWindow, html) {
  google.maps.event.addListener(marker, 'click', function() {
    infoWindow.setContent(html);
    infoWindow.open(map, marker);
    map.setCenter(marker.getPosition());
  });
}

function downloadUrl(url, callback) {
  var request = window.ActiveXObject ?
      new ActiveXObject('Microsoft.XMLHTTP') :
      new XMLHttpRequest;

  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      request.onreadystatechange = doNothing;
      callback(request, request.status);when making an AJAX request
    }
  };

  request.open('GET', url, true);
  request.send(null);
}

function doNothing() {}

//]]>
代码语言:javascript
复制
<body  onload="load()">

    <div class="contact">
    <div class="map" id="map"></div>
    </div>

</body> 

​

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-15 14:32:52

我使用过谷歌图表:https://developers.google.com/chart/?hl=es。

Google图表与JSON一起工作,我可以在您的代码中看到一个JSON结构,然后如果您是在PHP上编程,您可以使用json_encode和json_decode函数来生成正确的JSON结构。这很简单,您必须对数据库执行查询,然后,只需将数据组织在JSON结构中。

这是关于JSON函数的文档:http://www.php.net/manual/en/book.json.php

我希望这些信息对你有帮助。

祝好运。

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

https://stackoverflow.com/questions/23656789

复制
相关文章

相似问题

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