Report-Yahoo YUI
開発者ブログ: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
});
}