Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hello friends ..

i am trying to do google line chart..

i have done with coding ..But it is not displaying ..can u identify the error.


source code :

C#
StringBuilder str = new StringBuilder();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            chart_bind();
        }
    }

    private DataTable GetData()
    {
        CRMBLL objBAL = new CRMBLL();
        CommonFunctions comObj = new CommonFunctions();
        DataSet ds = comObj.ExecuteDataset("select * from dbo.repo");
        var test = ds;
        //DataSet ds = objBAL.DisplayWeeklyReportLeads("All", "presentweek", "crm0000003");
        DataTable dt = new DataTable();
        dt = ds.Tables[0];
        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', 'year');
            data.addColumn('number', 'contacted');
            data.addColumn('number', 'qualified');
            data.addColumn('number', 'demodone');
             

            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]["year"].ToString() + "');");
                str.Append("data.setValue(" + i + "," + 1 + "," + dt.Rows[i]["contacted"].ToString() + ") ;");
                str.Append("data.setValue(" + i + "," + 2 + "," + dt.Rows[i]["qualified"].ToString() + ") ;");
                str.Append("data.setValue(" + i + "," + 3 + "," + dt.Rows[i]["demodone"].ToString() + ");");

            }
            str.Append("   var chart = new google.visualization.LineChart(document.getElementById('chart_div'));");
            str.Append(" chart.draw(data, {width: 599, height: 400,color: 'Green',");
            str.Append("hAxis: {title: 'Year', titleTextStyle: {color: 'red'}},");
            str.Append(@"series: {0:{color:'#676767',lineWidth:2,pointShape: 'star',pointSize:10,dataOpacity: 2.0,},
                                  1:{color:'#00b0f0',lineWidth:2,pointShape: 'star',pointSize:10,dataOpacity: 2.0,},
                                  2:{color:'green',lineWidth:2, pointShape: 'star',pointSize:10,dataOpacity: 2.0,},
                                     }");
            str.Append("}); }");
            str.Append("</script>");
            lt.Text = str.ToString().TrimEnd(',').Replace('*', '"');
        }
        catch
        { }
    }



html code:

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">

     <title>GIG</title>
         <script type="text/javascript" src="https://www.google.com/jsapi"></script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Literal ID="lt" runat="server"></asp:Literal>
    </div>
    <div id="chart_div"></div>
    </form>
</body>
</html>
Posted
Updated 1-Nov-15 23:58pm
v2

1 solution

Just mark the following with single quote :
'visualization', '1',


You just need to make above amendment in following line:

str.Append(@"<script type="text/javascript"> google.load( visualization, 1, {packages:[*corechart*]});</script>


So final line will be :

str.Append(@"<script type="text/javascript"> google.load('visualization', '1', {packages:[*corechart*]});</script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900