显示从数据库到uv图表的数据? [英] Display data from database to uv chart?

查看:64
本文介绍了显示从数据库到uv图表的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Web应用程序中,我想将数据从数据库显示到UV图表。数据在运行时从数据库中获取。我怎么能这样做?



我尝试过:



我在互联网上搜索,但都是硬编码的例子。但是数据库在运行时的数据并希望在UV图表中显示。

In my web application, i want to display the data from database to UV chart. Datas are fetching from database at runtime. How can i to do that?

What I have tried:

I searched in internet but all are examples for hard coded. But data from database at the run time and want to display in UV chart.

推荐答案

试试这个样本



Try this sample

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="angular.min.js"></script>
    <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.2.2/d3.v3.min.js"></script>
    <script src="uvcharts.js"></script>
    <script src="jquery.min.js"></script>

    <script> 
        function getDataFromServer() {


.ajax({
type: POST
url: WebForm1.aspx / GetData
contentType:' application / json; charset = utf-8'
dataType:' json'
错误:function(){
alert( error);
},
成功:函数(结果){
var data = JSON.parse(result.d);
var graphdef = {
categories:[' uvCharts'],
数据集:{
' uvCharts' :数据

}
};
uv.chart(' Bar',graphdef);

}
});
}
.ajax({ type: "POST", url: "WebForm1.aspx/GetData", contentType: 'application/json; charset=utf-8', dataType: 'json', error: function () { alert("error"); }, success: function (result) { var data = JSON.parse(result.d); var graphdef = { categories: ['uvCharts'], dataset: { 'uvCharts': data } }; uv.chart('Bar', graphdef); } }); }


(function(){
getDataFromServer();

});
< / script >


< / head >
< body >
< 表格 id = form1 runat = 服务器 >
< div id = uv-div > < / div >
< / form >
< / body >
< / html >
(function () { getDataFromServer(); }); </script> </head> <body> <form id="form1" runat="server"> <div id="uv-div"></div> </form> </body> </html>
















public partial class WebForm1 : System.Web.UI.Page
   {
       [System.Web.Services.WebMethod]
       public static string GetData()
       {
           List<UVChartValues> lst = new List<UVChartValues>();
           lst.Add(new UVChartValues() { name = "2010", value = 32 });
           lst.Add(new UVChartValues() { name = "2011", value = 42 });
           lst.Add(new UVChartValues() { name = "2012", value = 52 });
           lst.Add(new UVChartValues() { name = "2013", value = 62 });
           lst.Add(new UVChartValues() { name = "2014", value = 72 });
           return new JavaScriptSerializer().Serialize(lst);

       }
   }
   public class UVChartValues
   {
       public string name { get; set; }
       public int value { get; set; }
   }


这篇关于显示从数据库到uv图表的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆