Hello all, 

I am writing to seek help in regards to binding database to  g.charts 
javascript.  If i link it with database schema 'sales', the charts render 
on the client-side, however if I use 'data' database schema, the charts 
does not render.  

INSERT INTO [dbo].[Sales]
           ([id]
           ,[year]
           ,[purchase]
           ,[sales])
     VALUES
           (<id, int,>
           ,<year, varchar(50),>
           ,<purchase, varchar(50),>
           ,<sales, varchar(50),>)
GO


INSERT INTO [dbo].[data]
           ([Id]
           ,[name]
           ,[data]
           ,[cover]
           ,[talk]
           ,[date])
     VALUES
           (<Id, int,>
           ,<name, varchar(50),>
           ,<data, varchar(50),>
           ,<cover, varchar(50),>
           ,<talk, varchar(50),>
           ,<date, varchar(50),>)
GO

The server end code I am using:

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.Text;
using System.Configuration;

public partial class Charts_07 : System.Web.UI.Page
{
    StringBuilder str = new StringBuilder();
    //Get connection string from web.config
    SqlConnection conn = new SqlConnection("Data 
Source=###\\SQLEXPRESS;Initial Catalog=Test;Persist Security Info=True;User 
ID=##;Password=###");

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            chart_bind();
        }
    }

    private DataTable GetData()
    {
        DataTable dt = new DataTable();
        conn.Open();
        string cmd = "select * from data";
        SqlDataAdapter adp = new SqlDataAdapter(cmd, conn);
        adp.Fill(dt);
        conn.Close();
        return dt;
    }

    private void chart_bind()
    {
        DataTable dt = new DataTable();
        try
        {
            dt = GetData();

            str.Append(@"<script type=text/javascript> google.load( 
*visualization*, *1*, {packages:[*corechart*]});
            google.setOnLoadCallback(drawChart);
            function drawChart() {
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'Id');
            data.addColumn('number', 'cover');
        
            
 
            data.addRows(" + dt.Rows.Count + ");");

            Int32 i;

            for (i = 0; i <= dt.Rows.Count - 1; i++)
            {
                //str.Append("data.setValue( " + i + "," + 0 + "," + "'" + 
dt.Rows[i]["id"].ToString() + "');");
                //str.Append("data.setValue(" + i + "," + 3 + "," + 
dt.Rows[i]["cover"].ToString() + ") ;");
                //str.Append("data.setValue(" + i + "," + 2 + "," + 
dt.Rows[i]["talk"].ToString() + ") ;");
                //str.Append("data.setValue(" + i + "," + 3 + "," + 
dt.Rows[i]["expences"].ToString() + ");");

                str.Append("data.setValue(" + i + "," + 0 + "," + 
dt.Rows[i]["Id"].ToString() + ");");
               str.Append("data.setValue(" + i + "," + 1 + ",'" + 
dt.Rows[i]["cover"].ToString() + "');");
                //str.Append("data.setValue(" + i + "," + 2 + ",'" + 
dt.Rows[i]["sales"].ToString() + "');");

            }

            str.Append("   var chart = new 
google.visualization.LineChart(document.getElementById('chart_div'));");
            str.Append(" chart.draw(data, {width: 660, height: 300, title: 
'Company Performance',");
            str.Append("hAxis: {title: 'Year', titleTextStyle: {color: 
'green'}}");
            str.Append("}); }");
            str.Append("</script>");
            lt.Text = str.ToString().TrimEnd(',').Replace('*', '"');
        }
        catch
        { }
    }

}



any help or guidance would be very much appreciated.  

-- 
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/groups/opt_out.

Reply via email to