0

I have a website in which I use Visual Studio's built in charts to visualize data.

I use c# methods to provide the chart with a datasource. However, google charts require the data on javascript methods. I have done some research on how to provide the data to a javascript method but I came up empty.

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
           google.load("visualization", "1", { packages: ["corechart"] });
           google.setOnLoadCallback(drawChart);
           function drawChart() {
               var data = new google.visualization.DataTable('<%=t%>');

               var options = {
                   title: 'Company Performance'
               };

               var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
               chart.draw(data, options);
           }
    </script> 

In this example I tried to create a data table called "t" on the c# side. I debugged and saw that data table is filled correctly but I keep getting "Table has no columns" error.

So, Can anyone provide a walkthrough on how to supply my MSSQL data into the javascript method used by google charts?

Thanks in advance

4

1 に答える 1

0

このGoogle折れ線グラフを見る

最初の変更

var data = new google.visualization.DataTable('<%=t%>');

var data = new google.visualization.arrayToDataTable('<%=t%>');

ここで説明したように、Google Line Chartsでは、C# の DataTable オブジェクトではなく、Array of Arrayを使用する必要があります。DataTable をArray of Arrayに変換し、それを arrayToDataTable() 関数に渡します。

于 2013-06-03T09:28:42.617 に答える