1.导入fusionchart的包
2.action中的写法
/**
* 环比
* @return
*/
public String hb_chart(){
String econIndexId=firstTeconIndexId;//getRequest().getParameter("econIndexId");
//System.out.println("同比指标"+econIndexId);
Integer year = Integer.valueOf(selectyear);
String econName = sysEconIndexManager.getNameByindexid(econIndexId);
List<Object[]> list= serviceEconIndexDatasManager.computeRate(econIndexId, year);
String strXML="<graph caption='"+econName+" "+year+"年环比增长统计' PYAxisName='total' SYAxisName='rate'" +
" showPercentValues='1' showPercentInToolTip='1' showLabels='1' " +
"showValues='1' numDivLines='10' decimalPrecision='0'" +
" anchorSides='10' anchorRadius='3' anchorBorderColor='009900' decimalPrecision='4' >";
/* String strXML="<graph caption='生产总值 季度统计' baseSize='10' PYAxisName='价格' SYAxisName='rate' showPercentValues='1'" +
" showPercentInToolTip='1' showLabels='1' showValues='1' numDivLines='10' decimalPrecision='4'" +
" anchorSides='10' anchorRadius='3' anchorBorderColor='009900' decimalPrecision='0'>"; */
strXML=strXML+"<categories>";
for(int i=0;i<list.size();i++){
Object[] oc =list.get(i);
strXML= strXML+"<category name='"+oc[2]+"月'/>";
}
strXML= strXML+"</categories>";
strXML=strXML+"<dataset seriesName='上月' renderAs='Line' parentYAxis='P' color='AFD8F8' showValues='0'>";
for(int i=0;i<list.size();i++){
Object[] oc =list.get(i);
strXML= strXML+"<set value='"+oc[4]+"' />";
}
strXML= strXML+"</dataset>";
strXML=strXML+"<dataset seriesName='"+year+"' renderAs='Line' parentYAxis='P' color='F6BD0F' showValues='0'>";
for(int i=0;i<list.size();i++){
Object[] oc =list.get(i);
strXML= strXML+"<set value='"+oc[3]+"' />";
}
strXML= strXML+"</dataset>";
strXML=strXML+"<dataset seriesName='环比增长率%' lineThickness='1' parentYAxis='S' color='8BBA00' showValues='0' numberSuffix='%25' >";
for(int i=0;i<list.size();i++){
Object[] oc =list.get(i);
strXML= strXML+"<set value='"+oc[5]+"' />";
}
strXML= strXML+"</dataset>";
strXML= strXML+"</graph>";
xmlStr=strXML;
return SUCCESS;
}
3.jsp中的使用
function createTB(strXML) {
var chart1 = new FusionCharts(
"/EconWarn/scripts/FusionChartsFree/Charts/MSCombiDY2D.swf",
"ChartId", "1030", "380");
chart1.setDataXML(strXML); //这里是从后台拿到的那个字符串
chart1.render("divtb"); //显示位置
}