博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Asp .net MVC4 利用Highcharts.js 生成曲线图
阅读量:6653 次
发布时间:2019-06-25

本文共 3554 字,大约阅读时间需要 11 分钟。

一、先来看看效果

  

二、前台实现代码

  1、引入相对应得css及Javascript文件

        <link href="~/Content/css/bootstrap.css" rel="stylesheet" />

        <link href="~/Content/css/css.css" rel="stylesheet" />
        <script src="~/Scripts/jquery-1.8.2.min.js"></script>
        <script src="~/Scripts/js/bootstrap.min.js"></script>
        <script src="~/Scripts/js/datepicker/WdatePicker.js"></script>
        <script src="~/Scripts/js/highcharts.js"></script>
        <script src="~/Scripts/js/exporting.js"></script>

  <style type="text/css">

        #AssayItems {
            width: 100%;  
            margin:10px auto;  
            text-align:center;
            vertical-align:middle;
            border: 1px solid #F8F8FF;
            display: none;
        }
        #Loading {
            text-align: center;
            display: none;
        }
    </style>

  2、统计按钮触发的事件

    $("#statiBtn").click(function () {

                    var Processid = $("#Process_PTR").children('option:selected').val();
                    ItemNo = $("#ItemNo").children('option:selected').val();
                    selectTit = $("#ItemNo").children('option:selected').text();
                    v = $("#Process_PTR").children('option:selected').text();
                    var begintime = $("#beginDate").val();
                    var lasttime = $("#lastDate").val();
                    LoadMEIRange(ItemNo,currRV);
                    $.ajax({
                        type: "POST",
                        url: '../StatisticsAssay/LoadCharts',
                        data: { 'Process_PTR': Processid, 'ItemNo': ItemNo, 'beginDate': begintime, 'lastDate': lasttime },
                        dataType: "json",
                        error: function (request) {
                            alert("Connection error");
                        },
                        beforeSend: function () {
                            //加载图标
                            $("#Loading").show();
                            $("#AssayItems").hide();
                        },
                        success: function (result) {
                            $("#AssayItems").show();
                            var assalyData = result;
                            var assaly = eval('(' + assalyData + ')');
                            var assalyd = eval('(' + assaly + ')');
                            var timeArr = new Array();
                            var resArr = new Array();
                            $.each(assalyd.ds, function (i, idtem) {
                                timeArr[i] = idtem.Timer; // 时间值
                            });
                            $.each(assalyd.res, function (i, idtem) {
                                resArr[i] = idtem.Result; // 检测结果
                            });
                            //加载曲线图
                            LoadCharts(timeArr, resArr);
                            $("#Loading").hide();
                        }
                    });
                    //防止Ajax页面提交后被刷新
                    //return false;
                });

  3、生成曲线图

  function LoadCharts(t,c)

        {
            Highcharts.setOptions({
                lang: {
                    printChart: "打印图表",
                    downloadJPEG: "下载JPEG 图片",
                    downloadPDF: "下载PDF文档",
                    downloadPNG: "下载PNG 图片",
                    downloadSVG: "下载SVG 矢量图",
                    exportButtonTitle: "导出图片"
                }
            });
            $('#AssayItems').highcharts({
                chart: {
                    type:'line'
                },
                title: {
                    text:''+v+'化验分析曲线图',
                    x: -20
                },
                xAxis: {//X轴标签
                    categories: t,
                    labels: {
                        rotation: -25,
                        style: {
                            fontSize: '10px',
                            fontFamily: 'Verdana, sans-serif'
                        }
                    }
                },
                yAxis: {
                    title: {
                        text: '统计数'
                    },
                    plotLines: [{
                        value: SXNums,
                        color: 'red',
                        dashStyle: 'shortdash',  
                        width: 2,  
                        label: {  
                            text: 'MEI下范围('+SXNums+')'  
                        }  
                    },
                    {
                        value: MIDNums,
                        color: 'green',  
                        dashStyle: 'shortdash',  
                        width: 2,  
                        label: {  
                            text: 'MEI中范围(' + MIDNums + ')'
                        }  
                    },
                    {
                        value:XXNums,
                        color: 'red',  
                        dashStyle: 'shortdash',  
                        width: 2,  
                        label: {  
                            text: 'MEI上范围(' + XXNums + ')'
                        }  
                    }]
                },
                colors:
                [
                    '#00B2EE'
                ],  
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'middle',
                    borderWidth: 0
                },
                series: [
                {
                    name: '' + selectTit + '',
                    data: c
                }
                ]
            });
        }

 

二、后台实现代码

  1、获取Mei范围

  public ActionResult LoadMEIRange()

        {
            int itemno = 0;
            int processid = 0;
            string meiStr = "";
            if (Request["itemno"] != null && Request["itemno"].ToString() != "")
            {
                itemno = Convert.ToInt32(Request["itemno"].ToString());
                processid = Convert.ToInt32(Request["processid"].ToString());
            }
            else
            {
                itemno = 1;
                processid = 1;
            }
            string meiSql = "select MeiRange from Assay_ProcessDetails where Process_PTR="+processid+" and ItemNo="+itemno+"";
            DataTable dt = SqlHelper.QueryTable(meiSql);
            if (dt.Rows.Count > 0)
            {
                meiStr = dt.Rows[0]["MeiRange"].ToString();
            }
            return Content(meiStr);
        }

 

三、博客地址:http://www.cnblogs.com/Resources-blogs/p/6600107.html

转载于:https://www.cnblogs.com/Resources-blogs/p/6600107.html

你可能感兴趣的文章
社区投稿 | DBLE rule.xml 配置解析
查看>>
【技术性】Search知识
查看>>
区块链共识机制优缺点对比都是什么
查看>>
枚举的使用示例
查看>>
coredns 排错记
查看>>
PAT A1098 堆排序
查看>>
Vue 2.x 文件夹目录
查看>>
mongodb数组字段prefix匹配返回
查看>>
idea maven工程显示灰色(不亮)
查看>>
SpiderData新功能,DApp实时数据分类看
查看>>
前端开发中的Error以及异常捕获
查看>>
技术人的达摩克利斯之剑
查看>>
啥是佩奇排名算法
查看>>
分布式理论之2PC协议(2阶段提交协议)
查看>>
Python 函数式编程、装饰器以及一些相关概念简介
查看>>
Java基础知识整理之static修饰方法
查看>>
Docker简介、常用命令与实践(二)
查看>>
10分钟入门 CSS3 Animation
查看>>
移动端页面键盘出现“搜索”按键且实现提交功能
查看>>
每天一个设计模式·代理模式
查看>>