Thanks Daniel. I went through the links you had posted. Looks like the
examples show how to connect to excel sheets. I would like to use the php
example and mimic that to connect to the SQL Server database. But that
din't work because the example is using MySQL database and has mysql
connection objects. Wasn't sure what would be the sql server connection
objects to connect to a SQL Server.
I also tried using asp.net. My dataset is pulling the values from the
database but doesn't the page is blank. Below is what I took from one of
the forums. Can you please check and let me know what am I doing wrong.
aspx:
<asp:Literal ID="lt" runat="server"></asp:Literal>
<div id="chart_div" style="width: 550px; height: 400px;"></div>
C#:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack == false)
{
BindBarChart();
}
}
private DataTable GetBarData()
{
DataTable dt = new DataTable();
using (SqlConnection conn = new
SqlConnection(@"server=servername;uid=username;pwd=password;database=databasename"))
{
string cmd = "select UserID, UserFName from Users with(nolock)";
SqlDataAdapter adp = new SqlDataAdapter(cmd, conn);
adp.Fill(dt);
return dt;
}
}
private void BindBarChart()
{
StringBuilder str = new StringBuilder();
DataTable dt = new DataTable();
try
{
dt = GetBarData();
str.Append(@"<script type=text/javascript> google.load(
*visualization*, *1*, {packages:[*Table*]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'UserID');
data.addColumn('string', 'UserFName');
data.addRows(" + dt.Rows.Count + ");");
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
str.Append("data.setValue( " + i + "," + 1 + "," + "'" +
dt.Rows[i]["UserID"].ToString() + "');");
str.Append("data.setValue(" + i + "," + 0 + "," +
dt.Rows[i]["UserFName"].ToString() + ") ;");
}
str.Append("var chart = new
google.visualization.Table(document.getElementById('chart_div'));");
str.Append("chart.draw(data, {title:'Report'");
//str.Append("vAxis: { title: 'Client', titleTextStyle: {
color: 'red' } }");
str.Append("}); }");
str.Append("</script>");
lt.Text = str.ToString().TrimEnd(',').Replace('*', '"');
}
catch (Exception e) { throw e; }
}
}
Thanks again!
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.