Laxman Sharma

Laxman Sharma

  • NA
  • 55
  • 9.7k

Geomap with SQl table

Aug 5 2015 3:46 AM
Hello Sir ,
I am working on google chart and developing a application for the geomap ,I am fetching the data form the SQl table .Everything I am doing correct even system is not showing any error while debugging but Map is not displaying :My code is as under :
.aspx page :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="testchart.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', { 'packages': ['geomap'] });
google.setOnLoadCallback(drawMap);
$(function () {
//For Pie chart
$.ajax({
type: 'POST',
dataType: 'json',
contentType: 'application/json',
url: 'WebForm1.aspx/GetgeomapData',
data: '{}',
success:
function (response) {
google.setOnLoadCallback(drawMap(response.d));
},
error: function () {
alert("Error loading data!");
}
});
});
function drawMap(dataValues) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'City');
data.addColumn('number', 'FIC');
for (var i = 0; i < dataValues.length; i++) {
data.addRow([dataValues[i].EmployeeCity,dataValues[i].FIC]);
}
var options = {};
options['region'] = 'IN';
options['colors'] = [0xFF8747, 0xFFB581, 0xc06000]; //orange colors
var geomap = new google.visualization.geomap(document.getElementById('map_canvas'));
geomap.draw(data, options);
};
</script>
</head>
<body>
<div id='map_canvas'></div>
</body>
</html>
.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Web.Services;
namespace testchart
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
// Pie chart
[WebMethod]
public static List<employeeDetails> GetgeomapData()
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(@"Data Source=Data-SERVER;Initial Catalog=GISDATABASE;Integrated Security=True"))
{
con.Open();
SqlCommand cmd = new SqlCommand("select *from TestTable", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
con.Close();
}
List<employeeDetails> dataList = new List<employeeDetails>();
foreach (DataRow dtrow in dt.Rows)
{
employeeDetails details = new employeeDetails();
details.EmployeeCity = dtrow[0].ToString();
details.FIC = Convert.ToInt32(dtrow[1]);
dataList.Add(details);
}
return dataList;
}
public class employeeDetails
{
public string EmployeeCity { get; set; }
public object Value { get; set; }
public string MIROUND { get; set; }
public int FIC { get; set; }
}
}
}

Answers (1)