js从后台无法取值问题

前台代码

<script type="text/javascript">
        $(function () {
            var chart;
            $(document).ready(function () {
                chart = new Highcharts.Chart({
                    chart: {
                        renderTo: 'container',
                        type: 'line',
                        marginRight: 130,
                        marginBottom: 25
                    },
                    title: {
                        text: '新增用户趋势图',
                        x: -20 //center
                    },
                    subtitle: {
                        text: 'Source: tourol.cn',
                        x: -20
                    },
                    xAxis: {
                        categories: <%= json_dates %>
                    },
                    yAxis: {
                        title: {
                            text: '人数'
                        },
                        plotLines: [{
                            value: 0,
                             1,
                            color: '#808080'
                        }]
                    },
                    tooltip: {
                        formatter: function () {
                            return '<b>' + this.x + '</b><br/>' +
                          '新增加人数 ' + this.y;
                        }
                    },
                    legend: {
                        layout: 'vertical',
                        align: 'right',
                        verticalAlign: 'top',
                        x: -10,
                        y: 100,
                        borderWidth: 0
                    },
                    series: [{
                      name: '新增人数',
                      data: <%= json_addusers %>
                    }]
                });
            });

        });
        $(function () {
            $(".index_tap_item>a").click(function () {
                $(".nav-stacked>li").each(function () {
                    $(this).removeClass('active');
                    $("#liuserstatics").addClass('active');
                });
                $(".tab-pane").each(function () {
                    $(this).removeClass('active');
                    $("#userstatics").addClass('active');
                });
            });
        });
    </script>

后台代码

public partial class statics_Default : System.Web.UI.Page
{
    public string json_addusers = string.Empty;
    public string json_dates = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        getData();
    }

    private void getData()
    {
        System.Data.DataTable datas = DBUtility.DBExecuteUtil.querySqlTable(
            " SELECT COUNT(*) addusers,CONVERT(varchar(100), [RegistDate], 23) dates  FROM [FenxCloudZj].[dbo].[tourol_B2CUser]  group by CONVERT(varchar(100), [RegistDate], 23)");
        string json1 = "[";
        string json2 = "[";
        for (int i = (datas.Rows.Count > 10 ? 10 : datas.Rows.Count); i > 0; i--)
        {
            json1 += datas.Rows[i]["addusers"] + ",";
            json2 += """ + datas.Rows[i]["dates"] + "",";
        }
        json1 = json1.TrimEnd(',');
        json1 += "]";
        json_addusers = json1;
        json2 = json2.TrimEnd(',');
        json2 += "]";
        json_dates = json2;
    }
}

不能直接使用json_addusers在查询数据库后取值,要用json1来做变量,暂时没搞清楚为什么

原文地址:https://www.cnblogs.com/TivonStone/p/3532876.html