在vs中,如果要使用柱形圖,我們大多數(shù)使用第三方提供的插件,所以必須要引用樣式,這里我使用的是Highcharts-4.1.9插件,百度一下就可以下載到。
關(guān)鍵的js代碼:
<script src="../Highcharts-4.1.9/js/jquery-1.8.2.min.js"></script> <style type="text/CSS"> </style> <script type="text/javascript"> $(function () { $('#container').highcharts({ chart: { type: 'column' }, title: { text: '各科室出院人次統(tǒng)計(jì)' }, subtitle: { text: '柱形圖' }, xAxis: { type: 'category', labels: { rotation: -45, style: { fontSize: '13px', fontFamily: 'Verdana, sans-serif' } } }, yAxis: { min: 0, title: { text: '出院人次' } }, legend: { enabled: false }, tooltip: { pointFormat: '{series.name}: <b>{point.y}</b><br/>' }, series: <%= returnValue %>, dataLabels: { enabled: true, rotation: 0, color: '#FFFFFF', align: 'center', format: '{point.y}', // one decimal y: 10, // 10 pixels down from the top style: { fontSize: '13px', fontFamily: 'Verdana, sans-serif' } } }] }); }); </script>
//body里面內(nèi)容
<body>
<form id="form1" runat="server">
<div class="easyui-panel" style="padding: 5px; margin-top:10px;">
<script src="../Highcharts-4.1.9/js/highcharts.js" type="text/Javascript"></script>
<script src="../Highcharts-4.1.9/js/modules/exporting.js" type="text/javascript"></script>
<div id="container" style="min-width: 300px; height: 400px; margin: 0 auto"></div>
</div>
</form>
</body>
.net后臺(tái)獲取數(shù)據(jù)庫(kù)數(shù)據(jù)填充:
public string returnValue = "";public string containerHeight = "400px";//關(guān)鍵性代碼DataTable dt = ((DataSet)rs).Tables[0]; if (dt.Rows.Count > 0) { if (dt.Rows.Count > 4) { containerHeight = (dt.Rows.Count * 50).ToString() + "px"; } else { containerHeight = "200px"; } string dataY = "[{name: '總費(fèi)用',data: ["; foreach (DataRow dr in dt.Rows) { dataY += "['" + dr["名稱"].ToString() + "'," + dr["總費(fèi)用"].ToString() + "]" + ","; } returnValue = dataY + "]"; }
大功告成,柱形圖數(shù)據(jù)填充結(jié)束。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注