Código:
Imports System.Data Imports System.Data.SqlClient Imports System.Configuration Imports System.Web.Services Imports Newtonsoft.Json Class WebForm1 Inherits System.Web.UI.Page <WebMethod(EnableSession:=True)> _ Public Shared Function getData() As String Dim cn As New SqlConnection("Data source=.;initial catalog=Prueba;uid=sa;pwd=.") Dim cmd As New SqlCommand("select * from data", cn) cn.Open() Dim dr As SqlDataReader dr = cmd.ExecuteReader Dim data As List(Of ArrayList) = New List(Of ArrayList) While dr.Read Dim a As New ArrayList a.Add(dr(0)) data.Add(a) End While Dim str As String = JsonConvert.SerializeObject(data) Return str //RETORNA [[15.00],[42.00],[100.00],[18.00],[16.00],[13.00],[18.00],[57.00],[90.00],[95.00],[96.00],[120.00]] End Function End Class
la tabla data contiene numero decimales
esto es para generar mi grafico de linea:
Código:
//SERIES[] debe contener de la siguiente manera:<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <script type="text/javascript"> $(document).ready(function () { var options = { chart: { renderTo: 'container', defaultSeriesType: 'line' }, title: {}, xAxis: {}, yAxis: {}, series: [] }; $.ajax({ type: "POST", dataType: "json", data: "{}", contentType: "application/json; charset=utf-8", url: "WebForm1.aspx/getData", success: function (items) { var obj = jsonParse(items.d); var series = { data: [] }; $.each(obj, function (itemNo, item) { series.data = obj.data; }); options.series.push(series); }, cache: false, error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); } }); chart = new Highcharts.Chart(options); }); </script> </head> <body> <div id="container" style="width:630px;height:420px;"> </div> </body> </html>
series: [{
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
}]
Estoy usando jquery ajax para recoger la data formateada en Json pero al momento de ejecutar no sale el grafico :C
Si alguien fuera tan amable de brindarme una ayuda.
Gracias C: