从融合表制作ColumnChart时出现问题

时间:2013-05-03 18:05:58

标签: javascript google-app-engine google-fusion-tables google-visualization

我正在尝试根据点击(使用我的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>

2 个答案:

答案 0 :(得分:0)

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

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

Fusion Tables info on creating a chart from FusionTables data

Working example

答案 1 :(得分: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>