问题描述
这个是ashx页面的usingNewtonsoft.Json;usingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Linq;usingSystem.Web;usingNewtonsoft.Json;namespaceHightCharts.Account{///<summary>///Count的摘要说明///</summary>publicclassCount:IHttpHandler{publicvoidProcessRequest(HttpContextcontext){context.Response.ContentType="text/plain";stringstr1=JsonConvert.SerializeObject(CreteDataTable());context.Response.Write(JsonConvert.SerializeObject(CreteDataTable()));context.Response.End();}publicboolIsReusable{get{returnfalse;}}publicDataTableCreteDataTable(){DataTabledataTable=newDataTable();///添加新的数据列dataTable.Columns.Add("Time",typeof(string));dataTable.Columns.Add("SumCount",typeof(int));dataTable.Columns.Add("IpCount",typeof(int));DataRowrow=dataTable.NewRow();//row["Time"]="00:00-01:00";row["Time"]="00:00-01:00";row["SumCount"]="500";row["IpCount"]="400";dataTable.Rows.Add(row);DataRowrow1=dataTable.NewRow();//row1["Time"]="01:00-02:00";row1["Time"]="01:00-02:00";row1["SumCount"]="600";row1["IpCount"]="300";dataTable.Rows.Add(row1);DataRowrow2=dataTable.NewRow();//row2["Time"]="02:00-03:00";row2["Time"]="02:00-03:00";row2["SumCount"]="500";row2["IpCount"]="400";dataTable.Rows.Add(row2);DataRowrow3=dataTable.NewRow();//row3["Time"]="03:00-04:00";row3["Time"]="03:00-04:00";row3["SumCount"]="700";row3["IpCount"]="300";dataTable.Rows.Add(row3);DataRowrow4=dataTable.NewRow();//row3["Time"]="03:00-04:00";row4["Time"]="04:00-05:00";row4["SumCount"]="300";row4["IpCount"]="200";dataTable.Rows.Add(row4);DataRowrow5=dataTable.NewRow();//row5["Time"]="04:00-05:00";row5["Time"]="05:00-06:00";row5["SumCount"]="800";row5["IpCount"]="600";dataTable.Rows.Add(row5);DataRowrow6=dataTable.NewRow();//row6["Time"]="05:00-06:00";row6["Time"]="06:00-07:00";row6["SumCount"]="700";row6["IpCount"]="500";dataTable.Rows.Add(row6);DataRowrow7=dataTable.NewRow();//row7["Time"]="06:00-07:00";row7["Time"]="08:00-09:00";row7["SumCount"]="550";row7["IpCount"]="450";dataTable.Rows.Add(row7);DataRowrow8=dataTable.NewRow();//row8["Time"]="07:00-08:00";row8["Time"]="09:00-10:00";row8["SumCount"]="650";row8["IpCount"]="420";dataTable.Rows.Add(row8);DataRowrow9=dataTable.NewRow();//row8["Time"]="07:00-08:00";row9["Time"]="10:00-11:00";row9["SumCount"]="750";row9["IpCount"]="320";dataTable.Rows.Add(row9);returndataTable;}}}--------------------------------------------------------------------------------------------------这个是aspx页面的,求指教怎么显示不了<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="HightChartsSql.aspx.cs"Inherits="HightCharts.HightChartsSql"%><!DOCTYPEhtml><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><scripttype="text/javascript"src="Scripts/jquery-1.8.2.min.js"></script><scripttype="text/javascript"src="Scripts/highcharts.js"></script><scripttype="text/javascript"src="Scripts/modules/exporting.js"></script><title></title></head><body><fieldset><legend>Hightchart柱状图案例</legend><div><scripttype="text/javascript">/*获取json数据开始*///定义变量$(document).ready(function(){//alert("1");varjsonXData=[];varjsonyD1=[];varjsonyD2=[];$.ajax({url:'/Account/Count.ashx',cache:false,async:false,success:function(data){varjson=eval("("+data+")");if(json.length>0){for(vari=0;i<json.length;i++){$("#txt_t1").val(json.length);varrows=json.Rows[i];varTime=rows.Time;varSumCount=rows.SumCount;varIpCount=rows.IpCount;jsonXData.push(Time);//赋值//<spanstyle="background-color:#ff0000;">//此处必须转型,不转型你就可以看到区别了</span><br>jsonyD1.push(parseInt(SumCount));jsonyD2.push(parseInt(IpCount));}$("#txt_t2").val(json.SumCount);varchart;chart=newHighcharts.Chart({chart:{renderTo:'containerliuliang',//放置图表的容器plotBackgroundColor:null,plotBorderWidth:null,defaultSeriesType:'column'//图表类型line,spline,area,areaspline,column,bar,pie,scatter},title:{text:'JQuery柱状图演示'},xAxis:{//X轴数据categories:['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],//x轴标签名称//categories:jsonXData,lineWidth:2,labels:{rotation:-45,//字体倾斜align:'right',style:{font:'normal13px宋体'}}},yAxis:{//Y轴显示文字lineWidth:2,title:{text:'浏览量/次'}},tooltip:{formatter:function(){return'<b>'+this.x+'</b><br/>'+this.series.name+':'+Highcharts.numberFormat(this.y,0);}},plotOptions:{column:{dataLabels:{enabled:true},enableMouseTracking:true//是否显示title}},series:[{name:'总流量',data:[18,25,46,78]},{name:'IP流量',data:[12,30,59,100]}]});}}});});</script><divid="containerliuliang"></div></div></fieldset></body></html>
解决方案
解决方案二:
解决方案三:
建议先把返回的josn放在页面上看看是什么原因
解决方案四:
引用2楼mimiooo1003的回复:
建议先把返回的josn放在页面上看看是什么原因
原因找到了varrows=json.Rows[i];这行错的,应该是varrows=json[i];如果以后出现这种错误,怎么发现啊,有类似断点调试的这种方法吗??
解决方案五:
浏览器F12你懂得
解决方案六:
引用4楼mimiooo1003的回复:
浏览器F12你懂得
哈哈,刚学,现在懂了,谢谢了