2

, how do I access it in the javascript. I am using javascriptamcharts and want to passvb.net`配列をjavascriptチャートにシリアライズするjson配列があります。コードを以下に示します。

VB

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    DataSetToJSON()
End Sub
Public Function SelectChartData(ByVal Name As String) As DataSet
    Dim sqlCmd As New SqlCommand
    Dim myData As New DataSet

    sqlCmd.CommandTimeout = 1200

    sqlCmd.CommandType = CommandType.StoredProcedure
    sqlCmd.CommandText = "SelectAmChartdata"

    sqlCmd.Parameters.Add("@Name", SqlDbType.VarChar)
    sqlCmd.Parameters("@Name").Value = Name

    Dim da As New dsSV1TableAdapters.tblGeneralTableAdapter

    da.Adapter.SelectCommand = sqlCmd

    sqlCmd.Connection = da.Connection
    sqlCmd.Connection.Open()
    da.Adapter.Fill(myData)

    sqlCmd.Dispose()
    sqlCmd = Nothing

    da.Connection.Close()
    da.Connection.Dispose()
    da.Connection = Nothing

    Return myData

End Function

Public Function DataSetToJSON()
    Dim dt As DataTable
    ds = SelectChartData("Weather")


    Dim dict As New Dictionary(Of String, Object)

    For Each dt In ds.Tables
        Dim arr(dt.Rows.Count) As Object

        For i As Integer = 0 To dt.Rows.Count - 1
            arr(i) = dt.Rows(i).ItemArray
        Next

        dict.Add(dt.TableName, arr)
    Next

    Dim json As New JavaScriptSerializer
    Return json.Serialize(dict)

End Function

ASPX

<script type="text/javascript">

//var chartData =  **Access Serverside Array**

    window.onload = function () {
    var chart = new AmCharts.AmSerialChart();
    chart.dataProvider = chartData;
    chart.categoryField = "country";
    chart.marginTop = 15;
    chart.marginLeft = 55;
    chart.marginRight = 15;
    chart.marginBottom = 80;
    chart.angle = 30;
    chart.depth3D = 15;

    var catAxis = chart.categoryAxis;
    catAxis.gridCount = chartData.length;
    catAxis.labelRotation = 90;

    var graph = new AmCharts.AmGraph();
    graph.balloonText = "[[category]]: [[value]]";
    graph.valueField = "visits"
    graph.type = "column";
    graph.lineAlpha = 0;
    graph.fillAlphas = 0.8;
    chart.addGraph(graph);

    chart.write('chartContainer');
}
</script
4

1 に答える 1

0

シリアル化されたデータを ASPX ページに直接ダンプできます。

<script type="text/javascript">

    var my_data = <%= DataSetToJSON() %>;

</script>

または、ASPX ページで使用できます。

<input type="hidden" id="my_data" clientidmode="static" runat="server" value="" />

コードビハインドでは:

my_data.Value = DataSetToJSON();

次に、 を使用document.getElementById('my_id').valueしてデータを取得し、次のような方法でデコードしJSON.parseてチャートに渡すことができます。

于 2012-11-19T09:55:28.640 に答える