, how do I access it in the javascript.
I am using javascript
amcharts and want to pass
vb.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