1

我有一个firePie.aspx页面,c#其中只有一个按钮,当它被点击时,

    protected void Button1_Click(object sender, EventArgs e)
    {
        string cadenaValor, valores;
        cadenaValor = "Audi(28%)','BMW(29%)','Mercedes(22%)" ;
        valores = "28,29,22";
        Response.Redirect("pieChart.aspx?values="+cadenaValor+"&valores="+valores);
    }

参数是带有逗号分隔值的字符串,我想将此值传递piechart.aspx给函数以javascript捕获这些参数并打印饼图,代码pieChart.aspx为:

<body>
<canvas id="cvs" width="450" height="300">[No canvas support]</canvas>        
<form id="frm" method="get" >
        <script type ="text/javascript" >
            var pie1 = new RGraph.Pie('cvs', ['<%=this.Request.QueryString["valores"]%>']);
        pie1.Set('chart.radius', 100);
        pie1.Set('chart.tooltips', ['<%=this.Request.QueryString["values"]%>']);
        pie1.Set('chart.labels', ['<%=this.Request.QueryString["values"]%>']);
        pie1.Set('chart.strokestyle', 'white');
        pie1.Set('chart.linewidth', 5);
        pie1.Set('chart.shadow', true);
        pie1.Set('chart.shadow.blur', 10);
        pie1.Set('chart.shadow.offsetx', 0);
        pie1.Set('chart.shadow.offsety', 0);
        pie1.Set('chart.shadow.color', '#000');
        pie1.Set('chart.text.color', '#999');

        var explode = 20;

        function myExplode (obj)
        {
            window.__pie__ = pie1;

            for (var i=0; i<obj.data.length; ++i) {
                setTimeout('window.__pie__.Explode('+i+',10)', i * 50);
            }
        }

        if (RGraph.isOld()) {
            pie1.Draw();

        } else if (navigator.userAgent.toLowerCase().indexOf('firefox') >= 0) {
            RGraph.Effects.Pie.RoundRobin(pie1);

        } else {
            /**
            * The RoundRobin callback initiates the exploding
            */

            RGraph.Effects.Pie.RoundRobin(pie1, null, myExplode);
            RGraph.Effects.Pie.Implode(pie1);
        }
    </script>          

 </form>
</body>

QueryString["valores"]不工作,如果我写原始字符串,我的意思是,28,29,22 在var pie1 = new RGraph.Pie('cvs'...它工作的行中,我认为出于任何原因javascript都没有识别这个值,但QueryString["values"]被正确捕获。你能帮我吗?

4

2 回答 2

0

Try to remove additional quotes in pieChart.aspx

<body>
<canvas id="cvs" width="450" height="300">[No canvas support]</canvas>        
<form id="frm" method="get" >
        <script type ="text/javascript" >
            var pie1 = new RGraph.Pie('cvs', [<%=this.Request.QueryString["valores"]%>]);
    pie1.Set('chart.radius', 100);
    pie1.Set('chart.tooltips', [<%=this.Request.QueryString["values"]%>]);
    pie1.Set('chart.labels', [<%=this.Request.QueryString["values"]%>]);
... 

and add quotes to code behind

protected void Button1_Click(object sender, EventArgs e)
    {
        string cadenaValor, valores;
        cadenaValor = "'Audi(28%)','BMW(29%)','Mercedes(22%)'" ; //added here
        valores = "28,29,22"; //No quotes here
        Response.Redirect("pieChart.aspx?values="+cadenaValor+"&valores="+valores);
    }
于 2012-11-23T22:14:57.700 回答
0

你能从查询字符串中捕捉到值吗?

我有一个 js 函数来从查询字符串中获取值:

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
        if(pair[0] == variable) {
            return pair[1];
        }
    }
    return(false);
}

您可以根据您的情况调用该函数getQueryVariable("valores")

看看这是否有帮助

于 2012-11-23T21:31:11.167 回答