日期:2014-05-16  浏览次数:20923 次

asp.net 饼形报表

前台:

 <script src="../../js/jquery-1.7.2.min.js" type="text/javascript"></script>
 <script src="../../js/tagchange.js" type="text/javascript"></script>
    <script src="../../js/highcharts.js" type="text/javascript"></script>

<script type="text/javascript">
          $(document).ready(function() {
           var chart = new Highcharts.Chart({
                  <%=chart %>
             });
         });
     </script>

<div id="visualization" style="width:800px; height:600px;"></div>用于存放饼形图


后台:

public StringBuilder chart = new StringBuilder();
        private void GetChart()
        {
            DataSet ds = new DataSet();
            ds = apryManager.QueryDataChart();  //获取dataset数据
            string count = (Convert.ToInt32(ds.Tables[0].Rows[0]["num"].ToString()) + Convert.ToInt32(ds.Tables[0].Rows[1]["num"].ToString()) + Convert.ToInt32(ds.Tables[0].Rows[2]["num"].ToString())).ToString();


            StringBuilder pie = new StringBuilder();
            pie.Append(" chart: {  renderTo: 'visualization', marginTop: 30, marginBotton: 0,plotBackgroundColor: null,plotBorderWidth: null,plotShadow: false,plotBackgroundColor:'#FFFFFF', backgroundColor:'#FFFFFF'},");   //renderTo: 'visualization' 为div的id
            pie.Append(" title: { text: '安全评价师共" + count + "名 ',enabled: true},");
            pie.Append("colors: ['#BADE62','#E70E00','#FEB904','#000'],");
            pie.Append(" tooltip: {formatter: function() { return '<b>'+ this.point.name +'</b>: '+ this.y+'<b>'+'人'+'</b>';} },");
            pie.Append("exporting: { enabled: false},");
            pie.Append(" printing: { enabled: false},");
            pie.Append("legend: { enabled: true,itemStyle: {padding:'0px'},itemWidth:500,labelFormatter: function() { return this.name;}},");
            //pie.Append(" plotOptions: {  pie: { size:'100%', allowPointSelect: false, cursor: 'pointer', dataLabels: { enabled: true,color: 'white',distance: -28,formatter: function() {return Highcharts.numberFormat(this.percentage,1) +'%';} },showInLegend: true  } },");  //显示百分比
            pie.Append(" plotOptions: {  pie: { size:'90%', allowPointSelect: false, cursor: 'pointer', dataLabels: { enabled: true,fontsize:'20',color: 'white',distance: -28,formatter: function() {return this.y;} },showInLegend: true  } },");
            pie.Append("series: [{ type: 'pie', name: 'Browser share',data:  [");
            foreach (DataRow il