前台:
<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 ilist in ds.Tables[0].Rows)
{
string jb = string.Empty;
if (ilist["jb"].ToString() == "1")
{
jb = "一级安全评价师";
}
else if (ilist["jb"].ToString() == "2")
{
jb = "二级安全评价师";
}
else if (ilist["jb"].ToString() == "3")
{
jb = "三级安全评价师";
}
else if (ilist["jb"].ToString() == "0")
{
jb = "暂无级别安全评价师";
}
pie.AppendFormat("['{0}',{1}],", jb, ilist["num"].ToString());
}
pie.Remove(pie.Length - 1, 1);
pie.Append("]}] ");
chart.Append(pie);
}