JQuery和HighCharts: JavaScript图标库

本文介绍如何使用HighCharts和JQuery实现数据可视化。包括从前端发起数据请求到后端处理并返回JSON数据的过程,以及如何将这些数据在前端进行图表展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

JQuery

教程:http://www.w3school.com.cn/jquery/


HighCharts

教程:http://www.runoob.com/highcharts/highcharts-tutorial.html


Ticks:

1. 从数据库中取出的数据可以先转化为JSON格式:new JavaScriptSerializer().Serialize(List<Object>);

2. 处理数据请求的:ProcessRequest(HttpContext context)返回JSON数据。

    public class ProcessRequestClass : IHttpHandler
    {
        public static string dbConStr = ConfigurationManager.ConnectionStrings["DBConStr"].ToString();
        public void ProcessRequest(HttpContext context)
        {
            string parameterValue = context.Request["paramter"];
 
            string jsonStr = FetchDataFromDBAndConvert(parameterValue);

            context.Response.ContentType = "application/json";
            context.Response.Write(jsonstr);
            context.Response.End();
        }
    }
3. 前端展示的处理:请求数据
                $.ajax({
                    url: 'ProcessRequestClass.ashx',
                    type: 'POST',
                    dataType: 'json',
                    data: "parameter1=" + pValue1 + "&parameter2=" + pValue2,
                    timeout: 3000,
                    cache: false,
                    beforeSend: BeforeSendFunction, //What to do before the request was sent
                    error: ErrorFunction, //Action to do for error
                    success: ShowDataFunction //Action to do when load successfully
                })

4. 展示数据

                function ShowDataFunction(data) {
                    if (data == null || data.length == 0) {
                        $("#Container1").empty();
                        alert("data null!");
                        return;
                    }
                    var arrayData = eval(data); // json type to array
                    // Show data in graph
                    options.series = new Array();
                    options.chart.type = "line";
                    options.chart.renderTo = "Container1";
                    options.title.text = "Chart Title";
                    options.subtitle.text = "Chart Sub Title";
                    options.xAxis.categories = arrayData.map(function (x) { return x.field1; });
                    options.series.push({
                        "name": "Series1Name",
                        "data": arrayData.map(function (x) { return x.field2; }),
                        "lineWidth": 3
                    });
                    options.series.push({
                        "name": "Series2Name",
                        "data": arrayData.map(function (x) { return x.field3; }),
                        "dashStyle": "dash",
                        "lineWidth": 1,
                        "color": "#FF0000"
                    });
                    var chart = new Highcharts.Chart(options);
                }

 

5. 定义展示数据的ID元素:上面的例子可以看到要在Container1上展示,所以boday部分就需要定义这样一个ID。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值