繁体   English   中英

从.net代码后面将json值传递到highcharts

[英]passing json values to highcharts from .net code behind

var Javascriptxvalue= $.parseJSON($("#hdnXaxis").val());
var Javascriptyvalue= $.parseJSON($("#hdnYaxis").val());  

$(document).ready(DrawMyGraph1);
      function DrawMyGraph1() {

       chart = new Highcharts.Chart(
       {
        chart: {
            type: 'column',
            renderTo: 'container3',
            defaultSeriesType: 'area'

        },
        title: {
            text: ''
        },
        subtitle: {
            text: ''
        },
        xAxis: {
            categories: Javascriptxvalue,
            labels: {
                enabled: false
            }
        },
        yAxis: {
            title: {
                text: 'No of Patients'
            }
        },

        credits: {
            enabled: false
        },
        tooltip: {
            formatter: function () {
                return this.series.name + ' - ' + Highcharts.numberFormat(this.y, 0);
            }
        },
        series: Javascriptyvalue
    });

}

C#代码void FastMovingStocksBarChart(string date1,string date2,selperiod,sql字符串){DataSet dschart = new DataSet(); dschart = _obj_MIS.DoctorpatientreportChart(date1,date2,selperiod,sql); 列表lstXaxis = new List(); 列表lstcolors = new List();

    lstcolors.Add("#3366DD");
    //lstcolors.Add("#FFEE22");
    //lstcolors.Add("#33BBCC");
    lstcolors.Add("#CC0022");
    //lstcolors.Add("#FF0000");
    lstcolors.Add("#339900");
    lstcolors.Add("#FF7700");
    lstcolors.Add("#33BBCC");
    lstcolors.Add("#99EEEE");
    lstcolors.Add("#6699FF");
    lstcolors.Add("#9966BB");
    lstcolors.Add("#99BB66");
    lstcolors.Add("#FF7700");
    lstcolors.Add("#FFEE22");
    lstcolors.Add("#FFCBB9");
    lstcolors.Add("EAEC93");
    lstcolors.Add("D7FBE6");
    lstcolors.Add("FFCACA");

    for (int i = 0; i < dschart.Tables[0].Rows.Count; i++)
    {
        lstXaxis.Add(dschart.Tables[0].Rows[i]["Doctor Name"].ToString());

    }
    List<ChartEx> lstseries = new List<ChartEx>();
    int count = 0;
    for (int i = 0; i < dschart.Tables[0].Rows.Count; i++)
    {

        ChartEx oEx = new ChartEx();
        oEx.name = dschart.Tables[0].Rows[i]["Doctor Name"].ToString();
        //oEx.data.Add(Convert.ToInt32(dschart.Tables[0].Rows[i]["Patients"]));
        oEx.data = new List<int>() { Convert.ToInt32(dschart.Tables[0].Rows[i]["Patients"]) };
        oEx.color = lstcolors[count];
        lstseries.Add(oEx);

        count++;
        if (count >= lstcolors.Count)
         count = 0; 


    }
    //Convert X axis data to JSON
    JavaScriptSerializer oSerializer1 = new JavaScriptSerializer();
    hdnXaxis.Value = oSerializer1.Serialize(lstXaxis);




    //Convert Y axis data to JSON
    JavaScriptSerializer oSerializer2 = new JavaScriptSerializer();
    hdnYaxis.Value = oSerializer1.Serialize(lstseries);

}

我没有在图表函数中获取“ Javascriptxvalue”和“ Javascriptyvalue”的值

谁能帮我

问候Prabhu

大概“ hdnXaxis”是HiddenFieldControl服务器控件的ID吗? 也许身份证不是你想的

var Javascriptxvalue= $.parseJSON($("#"+ <%= hdnXaxis.ClientId %>).val());

代替通过输入传递字符串,您可以使用服务器标签将值直接注入到页面中。 像这样:

<%= "alert('" + MyPublicProperty + "')" %>

这应该提醒您注意后面代码中定义的属性的值。 然后可以将其设置为js变量,如下所示:

<%= "var Javascriptxvalue = '" + xProperty + "';"  %>

不过,您将需要直接在aspx / ascx / razor页面中运行这段代码来设置变量,但是我认为这比依赖具有特定ID的控件要好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM