Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将JSON数据从.NET WebHandler传递给使用新系列数据重新绘制饼图_C#_Json_Highcharts - Fatal编程技术网

C# 将JSON数据从.NET WebHandler传递给使用新系列数据重新绘制饼图

C# 将JSON数据从.NET WebHandler传递给使用新系列数据重新绘制饼图,c#,json,highcharts,C#,Json,Highcharts,我想创建一个显示默认饼图和几个按钮的页面。当用户单击按钮时,页面将从WebHandler获取新的JSON数据并重新绘制图表。我正在使用.NET2.0、C和web表单 我让这个WebHandler json.ashx生成json: public void ProcessRequest (HttpContext context) { String data = String.Empty; data += "[{\"Male\": 80.0}, {\"Female\":

我想创建一个显示默认饼图和几个按钮的页面。当用户单击按钮时,页面将从WebHandler获取新的JSON数据并重新绘制图表。我正在使用.NET2.0、C和web表单

我让这个WebHandler json.ashx生成json:

public void ProcessRequest (HttpContext context) {        
    String data = String.Empty;
    data += "[{\"Male\": 80.0}, {\"Female\": 20.0}]";
    context.Response.ContentType = "application/json";
    context.Response.Write(data);
}
以下是我在aspx页面上的脚本:

    var chart = null;

    $(document).ready(function () {

        var options = {
            chart: {
                renderTo: 'container',
                defaultSeriesType: 'pie'
            },
            tooltip: {
                formatter: function () {
                    return '<b>' + this.point.name + '</b>: ' + this.y + ' (' + this.percentage + '%)';
                }
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        color: '#000000',
                        connectorColor: '#000000',
                        formatter: function () {
                            return '<b>' + this.point.name + '</b>: ' + this.y + ' (' + this.percentage + '%)';
                        }
                    }
                }
            },
            series: [{
                data: [['Yes', 60], ['No', 40]]
            }]

        };

        var chart = new Highcharts.Chart(options);


        $("#Gender").click(function () {
            $.get('json.ashx', function (data) {
                options.series = data;
                var chart = new Highcharts.chart(options);
            });
        });

    });

当我点击性别按钮时,它不会生成新的图表。如何正确解析JSON数据并将其提供给新饼图的series.data?

Nvm,我解决了这个问题。我必须传递highcharts想要的Json格式


例如:[{type:pie,name:Fruits,data:[[Apple,43.0],[Pear,57.0]]}]

不要手动形成json字符串。使用,等等。不过我在.NET2.0上。DataContractJsonSerializer、JavaScriptSerializer不支持2.0。我真的不想使用第三方框架。c:data+=[{\Male\:80.0},{\Male\:20.0}],JS:data:[[Yes',60],[No',40]]。您的数据是对象数组还是数组数组?