`
keepwork
  • 浏览: 332454 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论
阅读更多
开发者博客:http://www.developsearch.com

/**
	 * 拼装统计报表 饼图 json yahooYui
	 * 
	 * @param json
	 * @param res
	 * @throws UnsupportedEncodingException 
	 * @throws Exception
	 */
	public void fetchContentTypeStatChartData(JSONObject json,GetContentTypeStateResponse res) throws UnsupportedEncodingException
	{
		 StringBuffer JSON_STR = new StringBuffer();
		 if( null != res.getContentTypes() && res.getContentTypes().size() > 0 )
		 {
			 JSON_STR.append("[");
			 ContentTypeState content = res.getContentTypes().get(0);
			 JSON_STR.append("{ response: '电子书刊', count: "+content.getBooks().substring(0,content.getBooks().length()-1)+" },");
			 JSON_STR.append("{ response: '媒体教材', count: "+content.getMedia().substring(0,content.getMedia().length()-1)+" },");
			 JSON_STR.append("{ response: '案例', count: "+content.getCaze().substring(0,content.getCaze().length()-1)+" },");
			 JSON_STR.append("{ response: '量规集', count: "+content.getGauge().substring(0,content.getGauge().length()-1)+" },");
			 JSON_STR.append("{ response: '教学工具和模板', count: "+content.getTemplate().substring(0,content.getTemplate().length()-1)+" },");
			 JSON_STR.append("{ response: '文献资料', count: "+content.getDocument().substring(0,content.getDocument().length()-1)+" },");
			 JSON_STR.append("{ response: '索引目录', count: "+content.getIndexCata().substring(0,content.getIndexCata().length()-1)+" },");
			 JSON_STR.append("{ response: '课程', count: "+content.getCourse().substring(0,content.getCourse().length()-1)+" }");
			 JSON_STR.append("]");
			 json.put("chartDataSource", JSON_STR.toString());
		 }
	}


    /**
	 * 拼装统计报表 柱状图 json yahooYui
	 * 
	 * @param json
	 * @param res
	 * @throws UnsupportedEncodingException 
	 * @throws Exception
	 */
	/*public void fetchSingleExerciseDetailChartData(JSONObject json,GetSingleExerciseDetailResponse res) throws UnsupportedEncodingException
	{
		 StringBuffer JSON_STR = new StringBuffer();
		 if( null != res.getDetails() && res.getDetails().size() > 0 )
		 {
			 JSON_STR.append("[");
		
			 String a_str = "{ category:'A', ";
			 String b_str = "{ category:'B', ";
			 String c_str = "{ category:'C', ";
			 String d_str = "{ category:'D', ";
			 String e_str = "{ category:'E', ";
			 for( int i=0; i<res.getDetails().size(); i++)
			 {
				 SingleExerciseDetail single = res.getDetails().get(i);
				 
				 a_str += "set"+i+" : "+single.getPercentA()+",";
				 b_str += "set"+i+" : "+single.getPercentB()+",";
				 c_str += "set"+i+" : "+single.getPercentC()+",";
				 d_str += "set"+i+" : "+single.getPercentD()+",";
				 e_str += "set"+i+" : "+single.getPercentE()+",";
			 }
			 a_str = a_str.substring(0,a_str.length()-1) + "},";
			 b_str = b_str.substring(0,b_str.length()-1) + "},";
			 c_str = c_str.substring(0,c_str.length()-1) + "},";
			 d_str = d_str.substring(0,d_str.length()-1) + "},";
			 e_str = e_str.substring(0,e_str.length()-1) + "}";
			 
			 JSON_STR.append(a_str);
			 JSON_STR.append(b_str);
			 JSON_STR.append(c_str);
			 JSON_STR.append(d_str);
			 JSON_STR.append(e_str);
			 JSON_STR.append("]");
			 
			 json.put("chartDataNum", res.getDetails().size());
			 json.put("chartDataSource", JSON_STR.toString());
		 }
	}



<!-- yahooyui start -->
<script src="<%=baseurl%>/js/yui/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script src="<%=baseurl%>/js/yui/build/element/element-min.js"></script>
<script src="<%=baseurl%>/js/yui/build/datasource/datasource-min.js"></script>
<script src="<%=baseurl%>/js/yui/build/json/json-min.js"></script>
<script src="<%=baseurl%>/js/yui/build/swf/swf-min.js"></script>
<script src="<%=baseurl%>/js/yui/build/connection/connection-min.js"></script>
<script src="<%=baseurl%>/js/yui/build/charts/charts-min.js"></script>
<style type="text/css">  
#chartdiv {  
    width: 1000px;  
    height: 400px;  
}  
.chart_title {  
    display: block;  
    font-size: 2.2em;  
    font-weight: bold;  
    margin-bottom: 0.4em;  
    text-align:center;
}  
</style> 
<!-- yahooyui end -->

//页面图形展示  饼图
if(data.chartDataSource!=null){
					    	YAHOO.widget.Chart.SWFURL = "${ctx}/js/yui/build/charts/assets/charts.swf";
					    	var chartJson = eval(data.chartDataSource);  
					    	var myDataSource = new YAHOO.util.DataSource(chartJson);
				            		myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
				            		myDataSource.responseSchema = {
				            		    fields: [ "response", "count" ]
				            };
				            var mychart = new YAHOO.widget.PieChart( "chartdiv", myDataSource,
				            {
			            			dataField: "count",
			            			categoryField: "response",
			            			style:
			            			{
			            				padding: 20,
			            				legend:
			            				{
			            					display: "right",
			            					padding: 10,
			            					spacing: 5,
			            					font:
			            					{
			            						family: "Arial",
			            						size: 13
			            					}
			            				}
			            			}
				            });
					    }


//页面图形展示  柱状图
					    if(data.chartDataSource!=null){
					    	YAHOO.widget.Chart.SWFURL = "${ctx}/js/yui/build/charts/assets/charts.swf";
					    	
					    	var _fields = "['category'," ;
					    	var _seriesDef = "[" ;
					    	for(i=0; i<data.chartDataNum; i++){
					    		if(i==(data.chartDataNum-1)){
					    			_fields += "'set"+i+"'";
					    			_seriesDef += "{displayName: '',yField: 'set"+i+"',style:{size:10} }";
					    		}else{
					    			_fields += "'set"+i+"',";
					    			_seriesDef += "{displayName: '',yField: 'set"+i+"',style:{size:10} },";
					    		}
					    	}
					    	_fields += "]";
					    	_seriesDef += "]";
					    	_fields = eval(_fields);  
					    	_seriesDef = eval(_seriesDef);  
					    	
					    	var chartJson = eval(data.chartDataSource);  
					    	var myDataSource = new YAHOO.util.DataSource(chartJson);
		            			myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSARRAY;
		            			myDataSource.responseSchema = {
		            		    	fields: _fields
		            			};
	            		    var mychart = new YAHOO.widget.ColumnChart( "chartdiv", myDataSource,  
	            		    {  
	            		        xField: "category",  
	            		        series: _seriesDef,
	            		        polling: 10000
	            		    });  
					    }



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics