如何获得谷歌折线图。? [英] how to get google line chart.?

查看:82
本文介绍了如何获得谷歌折线图。?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友..



i我试图做谷歌折线图..



i已经完成有编码..但它没有显示..你可以识别错误。





源代码:



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 :

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代码:






html code:

<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>

推荐答案

只需用单引号标记以下内容:
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>


这篇关于如何获得谷歌折线图。?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆