js图表控件:highcharts的应用(三)

发布时间:2020-03-30 22:33:35 作者:苍穹断雪
来源:网络 阅读:427

    线形图

    前台代码:

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

<!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 src="Scripts/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            var chart;
            $(document).ready(function () {
                chart = new Highcharts.Chart({
                    chart: {
                        renderTo: 'container',
                        type: 'line'
                    },
                    title: {
                        text: '测试数据'
                    },
                    xAxis: {
                        categories: [<%=str %>]
                    },
                    yAxis: {
                        title: {
                            text: '单位/万元'
                        }
                    },
                    tooltip: {
                        formatter: function () {
                            return '<b>' + this.series.name + '</b><br/>' +
                    this.x + ': ' + this.y + '万元'+'<br/>所占百分比:'+changeTwoDecimal_f((this.y/<%=allcount %>)*100)+'%';
                        }
                    },
                    plotOptions: {
                        line: {
                            dataLabels: {
                                enabled: true
                            },
                            enableMouseTracking: true
                        }
                    },
                    series: [{
                        name:'测试数据',
                        data: [<%=strdata %>]
                    }]
                });
            });
            changeTwoDecimal_f = function (floatvar) {
                var f_x = parseFloat(floatvar);
                if (isNaN(f_x)) {
                    alert('function:changeTwoDecimal->parameter error');
                    return false;
                }
                var f_x = Math.round(floatvar * 100) / 100;
                var s_x = f_x.toString();
                var pos_decimal = s_x.indexOf('.');
                if (pos_decimal < 0) {
                    pos_decimal = s_x.length;
                    s_x += '.';
                }
                while (s_x.length <= pos_decimal + 2) {
                    s_x += '0';
                }
                return s_x;
            }
        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <script src="Scripts/highcharts.js" type="text/javascript"></script>
        <script src="Scripts/exporting.js" type="text/javascript"></script>
    <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
    </div>
    </form>
</body>
</html>

     后台代码:

     public string str = "";//文本
        public string strdata = "";//数据
        public double allcount = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadData();
        }
        protected void LoadData()
        {
            XmlDocument myDoc = new XmlDocument();
            myDoc.Load(Server.MapPath("DB_51aspx.xml"));

            XmlNode xn = myDoc.SelectSingleNode("//VoteInfo[ID='2']");//读取数据源

            XmlNodeList xnl = xn.SelectNodes("Item");

            double AllCount = 0;//总数

            for (int i = 0; i < xnl.Count; i++)
            {
                AllCount += Convert.ToSingle(xnl.Item(i).SelectSingleNode("Count").InnerText);
            }
            allcount = AllCount;
            for (int i = 0; i < xnl.Count; i++)
            {
                XmlNode xn0 = xnl.Item(i);
                strdata += xn0.SelectSingleNode("Count").InnerText+ ",";
                str += "\'" + xn0.SelectSingleNode("Title").InnerText + "\'" + ",";
            }
            strdata = strdata.Remove(strdata.Length-1,1);
            str = str.Remove(str.Length-1,1);
        }

      效果图展示:

      

js图表控件:highcharts的应用(三)

 

推荐阅读:
  1. 图表highcharts联合jquery ajax 后端取数据前端图表渲染
  2. js 控件

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

highcharts 线形图 js线形图

上一篇:在虚拟机中安装vmtools

下一篇:烂泥:学习Nagios(一):Nagios安装

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》