iT邦幫忙

0

fusionchart想畫出2條折線圖

  • 分享至 

  • xImage

大家好:
想問用fusionchart想畫出2條折線圖
但我卻只能畫一條,第2條就會讓頁面變空白....不然就是A線接B線後面畫下去...
以下是程式碼:

<%   
String pro[]={"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月","total"};  
    double proform[]=new double [13];   
    double proformt[]=new double [13];   
    for(int i=0;i<proform.length;i++){proform[i]=i*10;}
      for(int i=0;i<proformt.length;i++){proformt[i]=i*10+10;}
%>
<%
            String chartXML = "<chart __attributes__>__set__</chart>";  
             String chartXML1 = "<chart __attributes__>__set__</chart>";
            String attributeTemplate = "__key__=\"__value__\" ";
            
            String setXMLTemplate = "<set label=\"__label__\" value=\"__value__\" />";
             String setXMLTemplate1 = "<set label=\"__label__\" value=\"__value__\" />";
            Map<String, String> dataobj = new HashMap<String, String>();     
            for(int i=0;i<pro.length;i++){dataobj.put(pro[i] ,Double.toString(proform[i]));}
             for(int i=0;i<pro.length;i++){dataobj.put(pro[i] ,Double.toString(proformt[i]));}
            ArrayList<String> setList = new ArrayList<String>();
           
          for(int i=0;i<pro.length-1;i++)
            {                
                String tempSetTemplate = setXMLTemplate;
                tempSetTemplate = tempSetTemplate.replaceAll("__label__", pro[i]);
                tempSetTemplate = tempSetTemplate.replaceAll("__value__", Double.toString(proform[i]));   
                setList.add(tempSetTemplate);    
            } 
           for(int i=0;i<pro.length-1;i++)
            {                
                String tempSetTemplate = setXMLTemplate1;
                tempSetTemplate = setXMLTemplate1.replaceAll("__label__", pro[i]);
                tempSetTemplate = setXMLTemplate1.replaceAll("__value__", Double.toString(proformt[i]));   
                setList.add(tempSetTemplate);    
            } 
         
            StringBuilder chartAttributeString = new StringBuilder();          
            StringBuilder setAttributeString = new StringBuilder();
           
            for(String s: setList)
            setAttributeString.append(s);
                       
            chartXML = chartXML.replaceAll("__attributes__",  chartAttributeString.toString());          
            chartXML = chartXML.replaceAll("__set__",  setAttributeString.toString());
            chartXML1 = chartXML1.replaceAll("__attributes__",  chartAttributeString.toString());          
            chartXML1 = chartXML1.replaceAll("__set__",  setAttributeString.toString());
            FusionCharts1 columnChart= new FusionCharts1(
            "line",// chartType pie2d bar2d column2d gantt line pie2d            
                        "chart1",// chartId
                        "800","500",// chartWidth, chartHeight
                        "chart",// chartContainer
                        "xml",// dataFormat
                       chartXML,//dataSource
                    chartXML1
                    );  
  
            %>

我都在FusionCharts1中多加一個參數dataSource1了,但為何還是不行呢??

神威 iT邦研究生 4 級 ‧ 2018-04-23 11:44:28 檢舉
java的程式碼
```
public class FusionCharts1 {
private String constructorTemplate = "<script type=\"text/javascript\">FusionCharts.ready(function () {new FusionCharts(__constructorOptions__);});</script>";
private String renderTemplate = "<script type=\"text/javascript\">FusionCharts.ready(function () { FusionCharts(\"__chartId__\").render();});</script>";
private String[] chartOptions = new String[10];
private String chartDataSource = "",chartDataSource1 = "";
public FusionCharts1(String type, String id, String width, String height, String renderAt, String dataFormat, String dataSource, String dataSource1) {
this.chartOptions[0] = id;
this.chartOptions[1] = width;
this.chartOptions[2] = height;
this.chartOptions[3] = renderAt;
this.chartOptions[4] = type;
this.chartOptions[5] = dataFormat;
if(this.chartOptions[5].contains("url")) {
this.chartOptions[6] = "\""+dataSource+"\"";
this.chartOptions[7] = "\""+dataSource1+"\"";
} else {
this.chartOptions[6] = "__dataSource__";
this.chartOptions[7] = "__dataSource1__";
this.chartDataSource = this.addSlashes(dataSource.replaceAll("\n", ""));
this.chartDataSource1 = this.addSlashes(dataSource1.replaceAll("\n", ""));
}
}

private String addSlashes(String str) {
str = str.replaceAll("\\\\", "\\\\\\\\");
str = str.replaceAll("\\n", "\\\\n");
str = str.replaceAll("\\r", "\\\\r");
str = str.replaceAll("\\00", "\\\\0");
str = str.replaceAll("u003d", "=");
str = str.replaceAll("'", "\\\\'");
str = str.replaceAll("\\\\", "");
str = str.replaceAll("\"\\{", "{");
str = str.replaceAll("\"\\[", "[");
str = str.replaceAll("\\}\\]\"", "}]");
str = str.replaceAll("\"\\}\"", "\"}");
str = str.replaceAll("\\}\"\\}", "}}");
return str;
}
private String jsonEncode(String[] data){
String json = "{type: \""+this.chartOptions[4]+"\",renderAt: \""+
this.chartOptions[3]+"\",width: \""+this.chartOptions[1]+"\",height: \""+
this.chartOptions[2]+"\",dataFormat: \""+this.chartOptions[5]+"\",id: \""+
this.chartOptions[0]+"\",dataSource: "+this.chartOptions[6]+"}";
return json;
}
public String render() {
String outputHTML;
if(this.chartOptions[5].contains("url")) {
outputHTML = this.constructorTemplate.replace("__constructorOptions__", this.jsonEncode(this.chartOptions))+this.renderTemplate.replace("__chartId__", this.chartOptions[0]);
} else {
if("json".equals(this.chartOptions[5])) {
outputHTML = this.constructorTemplate.replace("__constructorOptions__", this.jsonEncode(this.chartOptions).replace("__dataSource__",this.chartDataSource))+this.renderTemplate.replace("__chartId__", this.chartOptions[0]);
outputHTML = this.constructorTemplate.replace("__constructorOptions__", this.jsonEncode(this.chartOptions).replace("__dataSource__",this.chartDataSource1))+this.renderTemplate.replace("__chartId__", this.chartOptions[0]);

} else {
outputHTML = this.constructorTemplate.replace("__constructorOptions__", this.jsonEncode(this.chartOptions).replace("__dataSource__","\'"+this.chartDataSource+"\'"))+this.renderTemplate.replace("__chartId__", this.chartOptions[0]);
outputHTML = this.constructorTemplate.replace("__constructorOptions__", this.jsonEncode(this.chartOptions).replace("__dataSource__","\'"+this.chartDataSource1+"\'"))+this.renderTemplate.replace("__chartId__", this.chartOptions[0]);

}
}
return outputHTML;
}
}

```
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答