c# – 如何隐藏谷歌可视化中的列

c# – 如何隐藏谷歌可视化中的列,第1张

概述我使用下面的代码来显示谷歌图表,我想在点击第一个图表时显示另一个图表,这里需要传递值ResourceId if (resourceDetails != null){ dataTable.Columns.Add("ResourceName", typeof(string)); dataTable.Columns.Add("ResourceId", typeof(int)); 我使用下面的代码来显示谷歌图表,我想在点击第一个图表时显示另一个图表,这里需要传递值ResourceID

if (resourceDetails != null){    datatable.Columns.Add("Resourcename",typeof(string));    datatable.Columns.Add("ResourceID",typeof(int));    datatable.Columns.Add("Planned",typeof(float));    datatable.Columns.Add("Actual",typeof(float));    foreach (var item in resourceDetails.distinct().ToArray())    {        dt = GetIndivIDualData(item.ResourceID,projectID);        if (dt.Rows.Count > 0)        {            for (int i = 0; i <= dt.Rows.Count - 1; i++)            {                DaTarow row = datatable.NewRow();                row["Resourcename"] = item.Resourcename;                row["ResourceID"] = item.ResourceID;                row["Planned"] = float.Parse(dt.Rows[i]["Planned"].ToString());                row["Actual"] = float.Parse(dt.Rows[i]["Actual"].ToString());                datatable.Rows.Add(row);            }        }    }    if (datatable.Rows.Count > 0)    {        stringBuilder.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','Resourcename');                                    data.addColumn('number','ResourceID');                                    data.addColumn('number','Planned');                                    data.addColumn({type: 'string',role: 'style'});                                    data.addColumn('number','Actual');                                    data.addColumn({type: 'string',role: 'style'});                ");        // data.addRows(" + datatable.Rows.Count + ");        for (int i = 0; i <= datatable.Rows.Count - 1; i++)        {            if (Convert.ToDecimal(datatable.Rows[i]["Planned"]) > Convert.ToDecimal(datatable.Rows[i]["Actual"]))            {                stringBuilder.Append("data.addRow(['" + datatable.Rows[i]["Resourcename"].ToString() + "'," + datatable.Rows[i]["ResourceID"].ToString() + "," + datatable.Rows[i]["Planned"].ToString() + ",\'color:DeepSkyBlue\'," + datatable.Rows[i]["Actual"].ToString() + ",\'color:green\']);");            }            else            {                stringBuilder.Append("data.addRow(['" + datatable.Rows[i]["Resourcename"].ToString() + "',\'color:red\']);");            }        }        stringBuilder.Append(" var chart = new Google.visualization.ColumnChart(document.getElementByID('chart_div'));");        stringBuilder.Append(" chart.draw(data,{wIDth: 660,height: 500,Title: 'Resource-Performance Graph',");        stringBuilder.Append("legend: {position: 'none'},");        stringBuilder.Append("hAxis: {Title: 'Resource',TitleTextStyle: {color: 'green'},slantedText:true},wIDth:'645',colors: ['DeepSkyBlue','green'],");        stringBuilder.Append("vAxis:{Title: 'Effort (Hr)',TitleTextStyle: {color: 'green'}}");        stringBuilder.Append("});");        stringBuilder.Append(" Google.visualization.events.addListener(chart,'onmouSEOver',function() {$('#chart_div').CSS('cursor','pointer');});");        stringBuilder.Append(" Google.visualization.events.addListener(chart,'onmouSEOut','default');});");        stringBuilder.Append("Google.visualization.events.addListener(chart,'select',function() {");        stringBuilder.Append("var selection = chart.getSelection();var row = selection[0].row;var col = selection[0].column;var rID = data.getValue(row,1); var pID = '" + projectID + "'; var pname = '" + projectname + "'; var resID = '" + Convert.ToInt32((Session["ResourceID"])) + "';");        stringBuilder.Append("location.href = '" + ConfigurationManager.AppSettings["Sitelink"].ToString() + "/IndivIDualGraph.aspx?pID=' + pID + '&pname=' + pname +'&pResID=' + rID ; ");        stringBuilder.Append("});");        stringBuilder.Append("}");        stringBuilder.Append("</script>");        lt.Text = stringBuilder.ToString().Replace('*','"');    }}

在这里,我使用ResouceID列将值作为参数传递,但它在图表中显示为列,如何隐藏此列?

解决方法 您可以使用 DataView Class隐藏列

var data = new Google.visualization.Datatable();data.addColumn('string','Resourcename');data.addColumn('number','ResourceID');data.addColumn('number','Planned');data.addColumn({type: 'string',role: 'style'});data.addColumn('number','Actual');data.addColumn({type: 'string',role: 'style'});var vIEw = new Google.visualization.DataVIEw(data);vIEw.hIDeColumns([1]);  // array of column indexes to hIDe

但是,在这种情况下,使用行属性可能是有意义的
它没有出现在图表中

您可以使用定义自己的属性
setRowProperty(rowIndex,name,value)

getRowProperty(rowIndex,name)

DataTable Class还具有Column和Cell PropertIEs的方法

总结

以上是内存溢出为你收集整理的c# – 如何隐藏谷歌可视化中的列全部内容,希望文章能够帮你解决c# – 如何隐藏谷歌可视化中的列所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1232030.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存