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

    线形图

    前台代码:

    <%@ 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=\'#\'" /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=\'#\'" /highcharts.js" type="text/javascript"></script>
        <script src=\'#\'" /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);
        }

      效果图展示:

      

线形图效果展示

 

你可能感兴趣的:(Highcharts,js线形图,线形图)