0

我正在尝试基于单击(使用我的 google.maps.event.addListener() )从两行(POTENTIAL_ 和 TOTAL_ROOF)创建数据的柱形图。

所以基本上一行数据会显示在图表上——基于用户的点击。

谁能帮我除掉杂草?……

我的融合表在这里:https ://www.google.com/fusiontables/DataSource?docid=1DGswslbC5ijqWHPJvOH1NH7vltkZIPURJun_L5I#rows:id=1

js函数1:

google.load('visualization', '1', {packages: ['corechart']});

function drawVisualization() {
    var queryText = encodeURIComponent("SELECT POTENTIAL_, TOTAL_ROOF, BLDG_ID FROM 1DGswslbC5ijqWHPJvOH1NH7vltkZIPURJun_L5I");
    google.visualization.drawChart({
    "containerId" : "visualization_div",
    "dataSourceUrl" : 'https://www.google.com/fusiontables/DataSource?docid=',
    "query" : "SELECT POTENTIAL_, TOTAL_ROOF FROM 1DGswslbC5ijqWHPJvOH1NH7vltkZIPURJun_L5I",
    "chartType" : "ColumnChart"
    })};

js函数2:

// Function call: Click Listener on layer using jquery
             google.maps.event.addListener(layer, 'click', function(e, drawVisualization) {
             $("#roof-panel-area").html(
             '<p><strong>Total Roof Area (sqft)</strong>: ' + '&nbsp;&nbsp;' + Math.round(e.row['TOTAL_ROOF'].value) +
             '<br><strong> Potential Roof Area (sqft)</strong>:' + '&nbsp;&nbsp;' + Math.round(e.row['POTENTIAL_'].value) +
             '<br><strong> Pitched or Flat Roof (?)</strong>:'+ '&nbsp;&nbsp;' +  e.row['PITCHED_OR'].value +
             '<br><strong> # of Panels per Roof Area :</strong>' + '&nbsp;&nbsp;' + Math.round(e.row['NUMBER_OF_'].value) + '</p>');
            });

        layer.setMap(map);

html:

<div id="sidebar-content-area" style="padding:5px;">
    <div id="intro" style="text-align: center; margin-top: 20px; display: none;">
        <p><i>Buildings are symbolized according to roof size, and the possibility of increased panel placement.</i><p>
    </div>
<div id="overview" style:"">
    <h3>Building Overview:</h3>
<p id ="roof-panel-area"></p>
<div id = "visualization_div"></div>
</div>
4

2 回答 2

0

惊人的。谢谢!这是答案:

js函数1:

function drawVisualization(e) {

        var data = google.visualization.arrayToDataTable([
          ['Area', 'Potential', 'Total'],
          ['Building',  Math.round(e.row['POTENTIAL_'].value), Math.round(e.row['TOTAL_ROOF'].value)],
        ]);

        var options = {
          title: 'Company Performance',
          hAxis: {title: 'Year', titleTextStyle: {color: 'red'}}
        };

        var chart = new google.visualization.ColumnChart(document.getElementById('visualization_div'));
        chart.draw(data, options);
    };

js函数2:

             google.maps.event.addListener(layer, 'click', function(e) {
         $("#roof-panel-area").html(
         '<p><strong>Total Roof Area (sqft)</strong>: ' + '&nbsp;&nbsp;' + Math.round(e.row['TOTAL_ROOF'].value) + 
         '<br><strong> Potential Roof Area (sqft)</strong>:' + '&nbsp;&nbsp;' + Math.round(e.row['POTENTIAL_'].value) + 
         '<br><strong> Pitched or Flat Roof (?)</strong>:'+ '&nbsp;&nbsp;' +  e.row['PITCHED_OR'].value + 
         '<br><strong> # of Panels per Roof Area :</strong>' + '&nbsp;&nbsp;' + Math.round(e.row['NUMBER_OF_'].value) +
         '</p>');
         drawVisualization(e);
        });

    layer.setMap(map);

}

html

        <div id="overview" style:"">
        <h3>Building Overview:</h3>
    <p id ="roof-panel-area"></p>
    <div id = "visualization_div" style="align: center; width: 230px; height: 260px;"></div>
    </div>
于 2013-05-03T19:34:59.587 回答
0

您的 dataSourceUrl 使用了错误的端点。

如果我使用“ http://www.google.com/fusiontables/gvizdata?tq= ”(而不是“ https://www.google.com/fusiontables/DataSource?docid= ”),我至少会得到一张图表。

关于从 FusionTables 数据创建图表的 Fusion Tables 信息

工作示例

于 2013-05-03T18:40:29.863 回答