无聊写了一个最简单的MVC4+Highcharts连数据库例子

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

乱搞了个数据库后面发现没定INT类型 直接将ID当数据显示了

效果图:

前端

1@{2Layout = null;3}45<!DOCTYPE html>67<html>8<head>9<metaname="viewport"content="width=device-width"/>1011<scriptsrc="~/Scripts/jquery-1.7.1.js"></script>12<scriptsrc="~/Scripts/Highcharts-4.0.3/js/highcharts.js"></script>13<scriptsrc="~/Scripts/Highcharts-4.0.3/js/modules/exporting.js"></script>14<scriptsrc="~/Scripts/Highcharts-4.0.3/js/highcharts-3d.js"></script>15<scripttype="text/javascript">1617$(function() {1819varvalues="";20vardata1=[];21varmonths=[];22//var a = [29.9, 71.5, 106.4, 129.2, 144]23$.Ajax({24url:'../Home/se',25type:'post',26dataType:"json",2728success:function(msg) {29//var values = JSON.stringify(msg)30//alert(msg.length)31for(vari=0; i<msg.length; i++) {32//alert("123")33//values += "11" + msg[i].tem + "11"34//var a= values.push(bb[i].tem);35data1.push(msg[i].id)36months.push(msg[i].months)37}3839varchart=newHighcharts.Chart({40chart: {41renderTo:'container',42type:'column',43margin:75,44options3d: {45enabled:true,46alpha:15,47beta:15,48depth:50,49viewDistance:2550}51},52title: {53text:'Chart rotation demo'54},55xAxis: {56categories:months5758},59yAxis: {60min:0,61title: {62text:'id'63}64},65subtitle: {66text:'Test options by dragging the sliders below'67},68plotOptions: {69column: {70depth:2571}72},73series: [{74data:data175}]76});77//Activate the sliders78$('#R0').on('change',function() {79chart.options.chart.options3d.alpha=this.value;80showValues();81chart.redraw(false);82});83$('#R1').on('change',function() {84chart.options.chart.options3d.beta=this.value;85showValues();86chart.redraw(false);87});88functionshowValues() {89$('#R0-value').html(chart.options.chart.options3d.alpha);90$('#R1-value').html(chart.options.chart.options3d.beta);91}92showValues();93}94})9596979899100101102});103</script>104<title>Index</title>105</head>106<body>107<divid="container"style="min-width: 700px; height: 400px"></div>108109<divid="sliders"style="min-width: 310px; max-width: 800px; margin: 0 auto;">110<table>111<tr>112<td>Alpha Angle</td>113<td>114<inputid="R0"type="range"min="0"max="45"value="15"/>115<spanid="R0-value"class="value"></span></td>116</tr>117<tr>118<td>Beta Angle</td>119<td>120<inputid="R1"type="range"min="0"max="45"value="15"/>121<spanid="R1-value"class="value"></span></td>122</tr>123</table>124</div>125</body>126</html>

View Code

后台

1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Linq;4usingSystem.Web;5usingSystem.Web.Mvc;6using表格.Models;78namespace表格.Controllers9{10publicclassHomeController : Controller11{12//13//GET: /Home/14columnPRictureEntities db =newcolumnprictureEntities();15publicActionResult Index()16{17returnView();18}19publicActionResult se()20{21222324vard = (frombindb.prcselectb).ToList();25List<Models.prc> bb = (fromddindb.prcselectdd).ToList();26returnJson(d, JsonRequestBehavior.AllowGet);27}2829}30}

View Code

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航