Charts 来自外部源的Google图表数据

Charts 来自外部源的Google图表数据,charts,google-visualization,Charts,Google Visualization,我正在使用C#webmethod向Google折线图提供数据。然而,我被数据的格式所困扰 目前我只能以列表(对象)格式发送数据。但我想用其他格式发送数据 这可能吗?请在下面找到我的代码片段: ASP页面 //调用以从ASP web方法获取数据 $.ajax({ type: "POST",`enter code here` contentType: 'application/json', data: '{}',

我正在使用C#webmethod向Google折线图提供数据。然而,我被数据的格式所困扰

目前我只能以列表(对象)格式发送数据。但我想用其他格式发送数据

这可能吗?请在下面找到我的代码片段:

ASP页面

//调用以从ASP web方法获取数据

$.ajax({
            type: "POST",`enter code here`
            contentType: 'application/json',
            data: '{}',
            url: 'AdminDashboard.aspx/GetChartData',
            beforeSend: function () { alert("before send"); },
            complete: function () { alert("complete"); },
            success: function (data) {

                var linedata1 = new google.visualization.arrayToDataTable(data.d);

                linedata1.insertColumn(0, 'date', linedata1.getColumnLabel(0));
                // copy values from column 1 (old column 0) to column 0, converted to Date
                for (var i = 0; i < linedata1.getNumberOfRows() ; i++) {
                    var val = linedata1.getValue(i, 1);
                    if (val != '' && val != null) {
                        var dateArray = val.split('/');
                        var year = dateArray[2];
                        var month = dateArray[0] - 1; // convert to javascript's 0-indexed months
                        var day = dateArray[1];
                        linedata1.setValue(i, 0, new Date(year, month, day));
                    }
                }
                // remove column 1 (the old column 0)
                linedata1.removeColumn(1);



                dashboard.bind(programmaticSlider, programmaticChart);
                dashboard.draw(linedata1);
            }

您可以以多种格式(JSON、CSV、TSV、HTML)提供数据,我强烈建议您使用JSON,您可以看到Google的默认结构:

我使用JSON格式工作

我已经发布了这个片段,可能会有帮助

//for dynamic data binding
            string jsonData = @"{ ""cols"" :[ {  ""label"" :  ""Type""  ,  ""type"" :  ""string"" },{ ""label"" :  ""Count""  ,  ""type"" :  ""number"" }], ""rows"" :[{""c"":[{""v"":""Mushrooms""},{""v"":3}]}," +
            @"{""c"":[{""v"":""Total""},{""v"":1}]}," +
            @"{""c"":[{""v"":""Open""},{""v"":1}]}," +
            @"{""c"":[{""v"":""Closed""},{""v"":1}]}," +
            @"{""c"":[{""v"":""In-Progress""},{""v"":2}]}]}";
关键是对每个值使用“双引号”。JSON识别“双引号”。
谢谢

谢谢马丁内斯。但我不知道如何创建JSON数据。我基本上是用C#创建一个列表,并将数据传递到google可视化表。您能帮我创建JSON数据吗?我不熟悉C#,但在您的服务AdminDashboard.aspx/GetChartData中,请尝试返回一个字符串,而不是返回一个列表,格式如下所述,谢谢Martinez。我按照您的指示,尝试以以下格式提供json数据字符串jsonData=“{cols':[{'id':'','label':'Topping','pattern':'','type':'string'},+“{'id':'','label':'Slices','pattern':'','type':'number'}+,'rows':[{'c':[{'v':'Mouss','f':'null},{'v':3,'f':null},{'c':'v':'f':'Onions',',{'v':1,'f':null}},{'c':[{'v':'Olives','f':null},{'v':1,'f':null}]},{'c':[{'v':'Zucchini','f':null},{'v':1,'f':null},“+”{'c':[{'v':'Pepperoni','f':null},{'v':2,'f':null}}”,但每次都说格式无效。
For clarity, my current data format i.e list data is as 
Date    Open Closed InProgress
1/2/13  2    0      0
2/2/13  1    2      0
3/3/13  0    0      1
4/3/13  0    1      0
//for dynamic data binding
            string jsonData = @"{ ""cols"" :[ {  ""label"" :  ""Type""  ,  ""type"" :  ""string"" },{ ""label"" :  ""Count""  ,  ""type"" :  ""number"" }], ""rows"" :[{""c"":[{""v"":""Mushrooms""},{""v"":3}]}," +
            @"{""c"":[{""v"":""Total""},{""v"":1}]}," +
            @"{""c"":[{""v"":""Open""},{""v"":1}]}," +
            @"{""c"":[{""v"":""Closed""},{""v"":1}]}," +
            @"{""c"":[{""v"":""In-Progress""},{""v"":2}]}]}";