从后面的代码调用谷歌树视图api [英] Call google tree view api from code behind

查看:104
本文介绍了从后面的代码调用谷歌树视图api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个Google树视图代码可以生成树视图。我稍微修改了一下以使其更简单。在这里。



 google.setOnLoadCallback(drawChart); 
function drawChart(){
var data = new google.visualization.DataTable();
data.addColumn(' string' ' 名称');
data.addColumn(' string' ' 经理');


data.addRows([[' Mike'' '],[' Jim'' Mike'],[< span class =code-string>' Alice'' Mike'],[' Bob'' Jim'],[' Carol'' Jim']]);

var chart = new google.visualization.OrgChart( document .getElementById(' chart_div'));
chart.draw(data,{allowHtml: true });
}





但要使其动态,我必须从db(来自C#页面)提供数据。因为我这样做了。



<前lang =c#> 受保护 void Page_Load( object sender,EventArgs e)
{
// 在页面上定义客户端脚本的名称和类型。
String csname1 = PopupScript;
输入cstype = this .GetType();

// 从Page类获取ClientScriptManager引用。
ClientScriptManager cs = Page.ClientScript;

// 检查启动脚本是否已注册。
if (!cs.IsStartupScriptRegistered(cstype,csname1))
{
StringBuilder cstext1 = new StringBuilder();
cstext1.Append( < script type = text / javascript>);

cstext1.Append( function drawChart(){);
cstext1.Append( var data = new google.visualization.DataTable(); );
cstext1.Append( data.addColumn('string','Name'); data.addColumn( 'string','经理'););
cstext1.Append( data.addRows([['Mike',''],''Jim ','Mike',['Alice','Mike'],['Bob','Jim'],['Carol','Jim']]););
cstext1.Append( var chart = new google.visualization.OrgChart(document.getElementById('chart_div') )););
cstext1.Append( chart.draw(data,{allowHtml:true}););
cstext1.Append( });
cstext1.Append( google.setOnLoadCallback(drawChart););
cstext1.Append( < / script>);

// cstext1.Append(< script type = text / javascript>) ;
// cstext1.Append(alert('s'););
// cstext1.Append(< / script>);

cs.RegisterStartupScript(cstype,csname1,cstext1.ToString());
}
}





但是加载后页面是空白的......没有数据显示...我的意图是使用自己的变量来更改2d数组,该变量将保存数组。我保持阵列原样。



请解决这个问题。



谢谢..

解决方案

如评论中所述,请检查以确保cstext1中没有任何语法错误。以这种方式构建字符串时很容易出现语法错误。


hi, i found this Google tree view code to generate a tree view. i modified it little bit to make it more simpler. here it is.

google.setOnLoadCallback(drawChart);
function drawChart() {
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'Name');
            data.addColumn('string', 'Manager');
            

            data.addRows([['Mike',''], ['Jim', 'Mike'], ['Alice', 'Mike'],['Bob', 'Jim'],['Carol', 'Jim']]);

            var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
            chart.draw(data, { allowHtml: true });
        }



but to make it dynamic i have to provide data from db(from C# page). for that i did this.

protected void Page_Load(object sender, EventArgs e)
        {
            // Define the name and type of the client scripts on the page.
            String csname1 = "PopupScript";
            Type cstype = this.GetType();

            // Get a ClientScriptManager reference from the Page class.
            ClientScriptManager cs = Page.ClientScript;

            // Check to see if the startup script is already registered.
            if (!cs.IsStartupScriptRegistered(cstype, csname1))
            {
                StringBuilder cstext1 = new StringBuilder();
                cstext1.Append("<script type=text/javascript>");
                
                cstext1.Append("function drawChart() {");
                cstext1.Append("var data = new google.visualization.DataTable();");
                cstext1.Append("data.addColumn('string', 'Name'); data.addColumn('string', 'Manager');");
                cstext1.Append("data.addRows([['Mike',''], ['Jim', 'Mike'], ['Alice', 'Mike'],['Bob', 'Jim'],['Carol', 'Jim']]);");
                cstext1.Append("var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));");
                cstext1.Append("chart.draw(data, { allowHtml: true });");
                cstext1.Append("}");
                cstext1.Append("google.setOnLoadCallback(drawChart);");
                cstext1.Append("</script>");

                //cstext1.Append("<script type=text/javascript>");
                //cstext1.Append("alert('s');");
                //cstext1.Append("</script>");

                cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
            }
        }



but after loading the page is blank..no data is showing.. my intention is to change the 2d array with an own variable which will hold the array. I kept the array as it was.

kindly solve the issue.

thanks..

解决方案

As mentioned in the comments, check to make sure that cstext1 does not have any syntax errors in it. It's easy to have syntax errors when you build up a string this way.


这篇关于从后面的代码调用谷歌树视图api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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