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



function drawVisualization() {var data = new 
google.visualization.DataTable();

    var jsonData = $.ajax({
        url: "/RestartSpringRestService/rest/siteIndicator",
        dataType: "json",
        async: false,
    }).responseText;
    

    var jsonObj = JSON.parse(jsonData);
    // Create our data table out of JSON data loaded from server.
    var size = 0;
    for(var sizeCount in jsonObj){
        size++;
    
        
    }
    
    
    
    data.addColumn('number', 'Lat', 'Lat');
    data.addColumn('number', 'Long', 'Long');
    data.addColumn('number', 'Value', 'Value');
    data.addColumn({type:'string', role:'tooltip'});

    for (var i = 1; i < size+1; i++) {
        
data.addRows([[jsonObj[i].latit,jsonObj[i].longi,jsonObj[i].siteIndicatorColor,jsonObj[i].siteNameRegion]]);
    }
    return data;
}

    var options = {
        colorAxis: { minValue : 1, maxValue : 3, colors: 
['#00CC00','#DBA901', '#FF3300']}, // green to red
        legend: {textStyle: {color: 'black', fontSize: 10}},
        backgroundColor: {fill:'#94DBFF',stroke:'#000000' ,strokeWidth:1 },
        datalessRegionColor: '#f5f5f5',
        displayMode: 'markers',
        enableRegionInteractivity: 'true',
        resolution: 'countries',
        sizeAxis: {minSize:5,  maxSize: 5},
        region:'world',
        keepAspectRatio: true,
        width:1200,
        height:500,
        tooltip: {textStyle: {color: '#444444'}}
    };
    
   
    
    
    
    
/*
    chart.draw(data, options);
    fetchlastupdate();
*/  
    

//setInterval(drawVisualization, 5000);
var chart;

function fetchlastupdate(){
 chart.draw(drawVisualization(), options);
document.getElementById('timestamp').textContent ='Last Refreshed : '+ new 
Date().toDateString() +'      '+ new Date().toTimeString();
setTimeout(fetchlastupdate, 5000);
}


function initialize(){
chart = new   
google.visualization.GeoChart(document.getElementById('visualization'));
google.visualization.events.addListener(chart, 'select', function() {
  
    /*var selectionIdx = chart.getSelection()[1].row;
    var siteName = data.getValue(selectionIdx, 0);*/
    //window.open('http://localhost:8080/siteCode?siteCode=' + siteName);
    var selection = chart.getSelection();
    if (selection.length > 0) {
        var row = selection[0].row;
        if (row != null) {
            var siteName = drawVisualization().getValue(row, 3);
            //alert("You clicked ID " + data.getValue(row, 3));
            var domainName =  window.location.hostname;
           
 
//window.open('http://'+domainName+':8080/RestartSpringRestService/siteCode?siteCode='
 
+ siteName);
           
 
window.open('http://'+domainName+':8080/RestartSpringRestService/siteDetails?siteCode='
 
+ siteName);
            
        }
    }
});
fetchlastupdate();
}




On Thursday, June 26, 2014 9:24:10 PM UTC+5:30, Andrew Gallant wrote:
>
> If you are getting that error message, it means you are either loading the 
> API incorrectly, or you aren't waiting for it to load before trying to use 
> API components.  It would help me to diagnose your issue if you could post 
> a complete example that demonstrates the problem.
>
> When you have that fixed, you need to remove the "new" keyword from the 
> arrayToDataTable call:
>
> var data = google.visualization.arrayToDataTable(dataArray);
>
>
> On Thursday, June 26, 2014 10:12:34 AM UTC-4, Nagendra Singh wrote:
>>
>> When I am hitting the url I am getting data in this form
>>
>> {"1":{"id":0,"bufferCount":24,"cpu":97.2,"memory":64.21965762722566,"siteName":null,"siteIndicatorColor":0,"dateOfOccurence":1402079370000}}
>>
>>
>>
>> Please suggest how can I map this to Column chart. I have tried using 
>> dataArray but an error- cannot read property 'arrayToDatatable' of undefined 
>> occurs... 
>>
>>
>>  var jsonObj = JSON.parse(jsonData);
>>         // Create our data table out of JSON data loaded from server.
>>         var size = 0;
>>         for(var sizeCount in jsonObj){
>>             size++;
>>         }
>>         var dataArray = new Array(size+1);
>>         dataArray[0] = new Array(2);
>>         dataArray[0][0] = 'bufferCount';
>>         dataArray[0][1] = 'cpu';
>>         dataArray[0][2] = 'memory';
>>         
>>         dataArray[0][3] = 'dateOfOccurence';
>>         
>>         //dataArray[0][2] = {type:'string', role:'tooltip'};
>>         var i = 1;
>>
>>     while(i < size+1){
>>             dataArray[i] = new Array(2);
>>             dataArray[i][0] = (jsonObj[i].bufferCount);
>>             dataArray[i][1] = (jsonObj[i].cpu);
>>             dataArray[i][2] = (jsonObj[i].memory);
>>             dataArray[i][3] =new Date(jsonObj[i].dateOfOccurence);
>>             //dataArray[i][2] = (jsonObj[i].bufferCount);
>>             i++;
>>         }
>>
>>     var data = new google.visualization.arrayToDataTable(dataArray);
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to