台灣最大程式設計社群網站
線上人數
1228
 
會員總數:243278
討論主題:188067
歡迎您免費加入會員
討論區列表 >> Java >> java jsp 畫圖問題
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
java jsp 畫圖問題
價值 : 30 QP  點閱數:350 回應數:15

樓主

黑~~
門外漢
0 17
494 43
發送站內信

大家好:
我用fusioncharts畫圖,我成功畫了一條折線圖
但我想在同一個chart畫第2條折線圖時都失敗
他會接在第一個折線圖的後面....
不知如何才能清楚畫出2之折線圖呢?
[code]
<%
String pro[]={"一月","二月","三月","四月"};
double proform[]=new double [4];
double proformt[]=new double [4];
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;}
%>
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="scripts/fusioncharts.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div id="chart"></div>
<%@page import="fusioncharts.FusionCharts1" %>
<%
String chartXML = "<chart __attributes__>__set__</chart>";

String setXMLTemplate = "<set label=\"__label__\" value=\"__value__\" />";
String setXMLTemplate1 = "<set label=\"__label__\" value=\"__value__\" />";
ArrayList<String> setList = new ArrayList<String>();
ArrayList<String> setList1 = new ArrayList<String>();
for(int i=0;i<pro.length;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;i++)
{
String tempSetTemplate = setXMLTemplate1;
tempSetTemplate = tempSetTemplate.replaceAll("__label__", pro[i]);
tempSetTemplate = tempSetTemplate.replaceAll("__value__", Double.toString(proformt[i]));
setList1.add(tempSetTemplate);
}
StringBuilder chartAttributeString = new StringBuilder();

StringBuilder setAttributeString = new StringBuilder();
for(String s: setList)
setAttributeString.append(s);
for(String s: setList1)
setAttributeString.append(s);
chartXML = chartXML.replaceAll("__attributes__", chartAttributeString.toString());
// Replace the data sets
chartXML = chartXML.replaceAll("__set__", setAttributeString.toString());

FusionCharts1 columnChart= new FusionCharts1(
"line",// chartType
"chart1",// chartId
"800","500",// chartWidth, chartHeight
"chart",// chartContainer
"xml",// dataFormat
chartXML//dataSource
);
%>
<%=columnChart.render()%>
</body>
</html>

[/code]
[code]

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 = "";
public FusionCharts1(String type, String id, String width, String height, String renderAt, String dataFormat, String dataSource) {
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+"\"";
} else {
this.chartOptions[6] = "__dataSource__";
this.chartDataSource = this.addSlashes(dataSource.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]);
} else {
outputHTML = this.constructorTemplate.replace("__constructorOptions__", this.jsonEncode(this.chartOptions).replace("__dataSource__","\'"+this.chartDataSource+"\'"))+this.renderTemplate.replace("__chartId__", this.chartOptions[0]);
}
}
return outputHTML;
}
}

[/code]
研究很久真的不知道哪裡錯了.....請大大協助,謝謝




搜尋相關Tags的文章: [ java ] , [ jsp ] , [ FusionCharts ] ,
本篇文章發表於2018-04-29 18:16
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
1樓
最有價值解答

Silent
檢舉此回應
你的格式不對
String chartXML = "<chart __attributes__>__set__</chart>"; //這一行
更換成
String chartXML = "<chart <dataset seriesname='line1'> __attributes__ </dataset>> <dataset seriesname='line2'> __set__ </dataset></chart> ";



官網文件
https://www.fusioncharts.com/dev/chart-guide/standard-charts/multi-series-charts

還有 你為什麼要寫的這麼麻煩...?
本篇文章回覆於2018-04-30 01:42
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
回應

Silent
檢舉此回應
用JSON格式 不是比較簡單?

建議前、後端的程式碼可以拆開來寫....

你這樣 讓其他人讀起來太痛苦了= = 會讓人很難維護
本篇文章回覆於2018-04-30 01:46
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
3樓
回應

Silent
檢舉此回應
sorry...還有其他的問題 我直接把jps的程式碼貼給你...

<!DOCTYPE html>
<%
Random rand = new Random();
String pro[] = { "一月", "二月", "三月", "四月","五月"};

double proform[] = new double[5];
double proformt[] = new double[5];
for (int i = 0; i < proform.length; i++) {
int number = rand.nextInt(10)+ 1;
proform[i] = i * number;
proformt[i] = i * number+10;
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="https://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div id="chart"></div>
<div id="chart2"></div>

<%@page import="web.beans.FusionCharts1" %>
<%@page import="java.util.*" %>
<%
String categories ="<categories> <category label=\"一月\" /><category label=\"二月\" /><category label=\"三月\" /><category label=\"四月\" /><category label=\"五月\" /> </categories>";
String chartXML = "<chart> "+categories+" <dataset seriesname=\"line1\"> __attributes__ </dataset> <dataset seriesname=\"line2\"> __set__ </dataset></chart>";

String setXMLTemplate = "<set label=\"__label__\" value=\"__value__\" />";
String setXMLTemplate1 = "<set label=\"__label__\" value=\"__value__\" />";
ArrayList<String> setList = new ArrayList<String>();
ArrayList<String> setList1 = new ArrayList<String>();
for (int i = 0; i < pro.length; i++) {
String tempSetTemplate = setXMLTemplate;
tempSetTemplate = tempSetTemplate.replaceAll("__label__", pro[i]);
tempSetTemplate = tempSetTemplate.replaceAll("__value__", Double.toString(proform[i]));
setList.add(tempSetTemplate);

tempSetTemplate = setXMLTemplate1;
tempSetTemplate = tempSetTemplate.replaceAll("__label__", pro[i]);
tempSetTemplate = tempSetTemplate.replaceAll("__value__", Double.toString(proformt[i]));
setList1.add(tempSetTemplate);
}
for (int i = 0; i < pro.length; i++) {
String tempSetTemplate = setXMLTemplate1;
tempSetTemplate = tempSetTemplate.replaceAll("__label__", pro[i]);
tempSetTemplate = tempSetTemplate.replaceAll("__value__", Double.toString(proform[i]));
setList.add(tempSetTemplate);

tempSetTemplate = setXMLTemplate1;
tempSetTemplate = tempSetTemplate.replaceAll("__label__", pro[i]);
tempSetTemplate = tempSetTemplate.replaceAll("__value__", Double.toString(proformt[i]));
setList1.add(tempSetTemplate);
}

StringBuilder line1 = new StringBuilder();
StringBuilder line2 = new StringBuilder();

for (String s : setList){
line1.append(s);
}
for (String s : setList1){
line2.append(s);
}

chartXML = chartXML.replaceAll("__attributes__", line1.toString());
// Replace the data sets
chartXML = chartXML.replaceAll("__set__", line2.toString());

System.out.println(line1.toString());
System.out.println(line2.toString());
System.out.println(chartXML);

FusionCharts1 columnChart = new FusionCharts1("msline", // chartType
"chart1", // chartId
"800", "500", // chartWidth, chartHeight
"chart", // chartContainer
"xml", // dataFormat
chartXML//dataSource
);
%>
<%=columnChart.render()%>
</body>
本篇文章回覆於2018-04-30 02:46
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
4樓
作者回應

黑~~
檢舉此回應
Silent大大好:
謝謝你的回覆,想再請教一些問題
[code]
String categories ="<categories> <category label=\"一月\" /><category label=\"二月\" /><category label=\"三月\" /></categories>";
-----更改後------
String categories = " ";
for (int i = 0; i < pro.length; i++) {
categories=categories+"<category label=\" "+pro[i]+" \" />";
}
[/code]
1. 我想把categories改成for迴圈,陣列方式輸入,但這樣他就不行了耶...為什麼?
2. 還有 seriesname=\"line1\名稱是不是只能寫死啊?我希望html那邊能做個checkbox,再將參數傳到seriesname
EX:104年105年選課人數比較.....seriesname=104, seriesname=105這樣
3. 如果我還要再抓地3條線,我是不是就還要寫一個line3?

這是我昨天努力寫的程式碼,雖然圖框有出來但是數字還是沒出來,格式我也有按照官方文件寫了
不知哪裡有問題
[code]

<%
String pro[]={"一月","二月","三月","四月"};
double proform[]=new double [4];
double proformt[]=new double [4];
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;}
%>
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="scripts/fusioncharts.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>

</head>
<body>
<div id="chart"></div>
<%@page import="fusioncharts.FusionCharts" %>
<%
String chartXML = "<chart __attributes__>__set__</chart>";
String setXMLTemplate1 = "<category label=\"__label__\" />";

String setXMLTemplate = "<dataset seriesname=\"__seriesname__\"><set value=\"__value__\" /> </dataset>";
ArrayList<String> setList = new ArrayList<String>();
for(int i=0;i<pro.length;i++)
{
String tempSetTemplate = setXMLTemplate1;
tempSetTemplate = tempSetTemplate.replaceAll("__label__", pro[i]);
setList.add(tempSetTemplate);
}
int u=2016;
for(int i=0;i<2;i++)
{
String tempSetTemplate = setXMLTemplate;
tempSetTemplate = tempSetTemplate.replaceAll("__seriesname__", Integer.toString(u+i));

for(int j=0;j<proform.length;j++){

tempSetTemplate = tempSetTemplate.replaceAll("__value__", Double.toString(proform[j]));

}

setList.add(tempSetTemplate);
}

StringBuilder chartAttributeString = new StringBuilder();
StringBuilder setAttributeString = new StringBuilder();

for(String s: setList)
setAttributeString.append(s);

chartXML = chartXML.replaceAll("__attributes__", chartAttributeString.toString());
// Replace the data sets
chartXML = chartXML.replaceAll("__set__", setAttributeString.toString());

FusionCharts columnChart= new FusionCharts(
"msline",// chartType
"chart1",// chartId
"800","500",// chartWidth, chartHeight
"chart",// chartContainer
"xml",// dataFormat
chartXML


);
%>
<%=columnChart.render()%>
</body>
</html>
[/code]
本篇文章回覆於2018-04-30 11:09
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
5樓
作者回應

黑~~
檢舉此回應
問題1已解決
問題2,3還沒
本篇文章回覆於2018-04-30 11:46
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
6樓
作者回應

黑~~
檢舉此回應
問題2也OK了
剩下問題3
因為我想用checkbox勾一條線~4條線不等
這樣我是不是就只能變數setXMLTemplate1~4了阿??
有沒有其他方法呢?
謝謝

本篇文章回覆於2018-04-30 11:52
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
7樓
回應

Silent
檢舉此回應
問題1、2你OK了 能把你目前最新的代碼給我?
因為問題3 跟問題2有關 我懶得去做...
直接用你的比較快 你也比較好理解
本篇文章回覆於2018-04-30 13:27
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
8樓
作者回應

黑~~
檢舉此回應
以下我的程式碼,還在努力修改中~~~
謝謝
[code]
<body>
<div id="chart"></div>
<div class="container">
<form method=post action=b.jsp>
<font size=5>
<input type=checkbox name=year value=2014> 2014
<input type=checkbox name=year value=2015> 2015
<input type=checkbox name=year value=2016> 2016
<input type=checkbox name=year value=2017> 2017
<input type=submit name=submit Value="submit">
</font>
</form>
</div>
</body>
<%
Random rand = new Random();
String pro[] = { "一月", "二月", "三月", "四月","五月"};
double proform[] = new double[5];
double proformt[] = new double[5];
for (int i = 0; i < proform.length; i++) {
int number = rand.nextInt(10)+ 1;
proform[i] = i * number;
proformt[i] = i * number+10;
}
String[] year={" "};
year = request.getParameterValues("year");

String categories = "<categories> ";
String u="2016";
for (int i = 0; i < pro.length; i++) {
categories=categories+"<category label=\" "+pro[i] +" \" />";
}
categories=categories+"</categories> ";
/*String count="";
for (int i = 0; i < year.length; i++) {
count=count+"<dataset seriesname=\" "+year[i]+"\">__attributes__ </dataset> ";
}*/
String chartXML = "<chart> "+categories+" <dataset seriesname=\""+u +"\"> __attributes__ </dataset> <dataset seriesname=\"line2\"> __set__ </dataset></chart>";
//String chartXML1 = "<chart> "+categories+count+"</chart>";
String setXMLTemplate = "<set label=\"__label__\" value=\"__value__\" />";
String setXMLTemplate1 = "<set label=\"__label__\" value=\"__value__\" />";
ArrayList<String> setList = new ArrayList<String>();
ArrayList<String> setList1 = new ArrayList<String>();
for (int i = 0; i < pro.length; i++) {
String tempSetTemplate = setXMLTemplate;
tempSetTemplate = tempSetTemplate.replaceAll("__label__", pro[i]);
tempSetTemplate = tempSetTemplate.replaceAll("__value__", Double.toString(proform[i]));
setList.add(tempSetTemplate);

tempSetTemplate = setXMLTemplate1;
tempSetTemplate = tempSetTemplate.replaceAll("__label__", pro[i]);
tempSetTemplate = tempSetTemplate.replaceAll("__value__", Double.toString(proformt[i]));
setList1.add(tempSetTemplate);
}
StringBuilder line1 = new StringBuilder();
StringBuilder line2 = new StringBuilder();

for (String s : setList){
line1.append(s);
}
for (String s : setList1){
line2.append(s);
}

chartXML = chartXML.replaceAll("__attributes__", line1.toString());
// Replace the data sets
chartXML = chartXML.replaceAll("__set__", line2.toString());

FusionCharts columnChart = new FusionCharts(
"msline", // chartType
"chart1", // chartId
"800", "500", // chartWidth, chartHeight
"chart", // chartContainer
"xml", // dataFormat
chartXML//dataSource
);

%>
<%=columnChart.render()%>

[/code]
本篇文章回覆於2018-04-30 15:43
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
9樓
不錯的參考

Silent
檢舉此回應
OK了 jps的程式碼

<!DOCTYPE html>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"
src="https://static.fusioncharts.com/code/latest/fusioncharts.js"></script>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div id="chart"></div>


<div id="chart"></div>
<div class="container">
<form method="post" action="test">
<font size=5> <input type="checkbox" name="year" multiple="multiple" value="2014">
2014 <input type="checkbox" name="year" multiple="multiple" value="2015"> 2015 <input
type="checkbox" name="year" multiple="multiple" value="2016"> 2016 <input
type="checkbox" name="year" multiple="multiple" value="2017"> 2017 <input type=submit
name=submit Value="submit">
</font>
</form>
</div>
</body>


<%@page import="web.beans.FusionCharts"%>
<%@page import="java.util.*"%>
<%!
private String createDataSetXml(String seriesname,String pro[],double proform[]){
String setXMLTemplate = "<set label=\"__label__\" value=\"__value__\" />";
ArrayList<String> setList = new ArrayList<String>();
for (int i = 0; i < pro.length; i++) {
String tempSetTemplate = setXMLTemplate;
tempSetTemplate = tempSetTemplate.replaceAll("__label__", pro[i]);
tempSetTemplate = tempSetTemplate.replaceAll("__value__", Double.toString(proform[i]));
setList.add(tempSetTemplate);
}
StringBuilder line = new StringBuilder();
for (String s : setList) {
line.append(s);
}

String dataSetXml = "<dataset seriesname=\""+seriesname+"\">";
dataSetXml+=line.toString();
dataSetXml+="</dataset>";
return dataSetXml;
}


private double[] getRandProform(String pro[]){
Random rand = new Random();
double proform[] = new double[pro.length];
for (int i = 0; i < proform.length; i++) {
int number = rand.nextInt(10) + 1;
proform[i] = i * number;
}
return proform;
}
%>
<%


String pro[] = { "一月", "二月", "三月", "四月", "五月" };


String categories = "<categories> ";
for (int i = 0; i < pro.length; i++) {
categories = categories + "<category label=\"" + pro[i] + "\" />";
}
categories = categories + "</categories> ";




String years[]= request.getParameterValues("year");
if(years!=null && years.length>0){
String chartXML = "<chart> " + categories + " __allDataSet__ </chart>";

List<String> dataSetList = new ArrayList<String>();
for(String y:years){
System.out.println(y);
String dataSet = createDataSetXml(y,pro,getRandProform(pro));
dataSetList.add(dataSet);
}
String allDataSetXml="";
for(String dataSet :dataSetList){
allDataSetXml+=dataSet;
}

chartXML = chartXML.replaceAll("__allDataSet__", allDataSetXml);
FusionCharts columnChart = new FusionCharts("msline", // chartType
"chart1", // chartId
"800", "500", // chartWidth, chartHeight
"chart", // chartContainer
"xml", // dataFormat
chartXML//dataSource
);
out.write(columnChart.render());
}


%>
</body>
</html>
本篇文章回覆於2018-04-30 17:02
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
10樓
回應

Silent
檢舉此回應
form 裡面的action 你再改成自己的page
本篇文章回覆於2018-04-30 17:04
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
11樓
作者回應

黑~~
檢舉此回應
Silent 大大,謝謝
原來可以用call function的方式來完成,我都沒想到
看來還要多磨練...
感謝
本篇文章回覆於2018-05-02 09:42
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
12樓
作者回應

黑~~
檢舉此回應
Silent 大大你好,能再請教你問題嗎?
我有自己改程式,其實我是連資料庫+畫圖
我資料庫抓出來的值也都OK
但是我畫卻只能畫一條線....第二條線都跑不出來.....
想問該怎麼做會比較好?
謝謝
以下是程式碼:
[code]

<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="scripts/fusioncharts.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="container">
<form method=post action=line.jsp>
<input type="checkbox" name="year" multiple="multiple" value="2016"> 2016
<input type="checkbox" name="year" multiple="multiple" value="2017"> 2017
<input type="checkbox" name="year" multiple="multiple" value="2018"> 2018
<input type="checkbox" name="year" multiple="multiple" value="2019">2019
<input type=submit name=submit Value="submit">
</form>
</div>
<div id="chart"></div>
</body>
</html>
<%!
private String createDataSetXml(String seriesname,String pro[],String years[],double proform[][]){
String setXMLTemplate = "<set label=\"__label__\" value=\"__value__\" />";
ArrayList<String> setList = new ArrayList<String>();
StringBuilder line = new StringBuilder();
String dataSetXml = "";
for(int i=0;i<years.length;i++) {
for (int j = 0; j < pro.length; j++) {
String tempSetTemplate = setXMLTemplate;
tempSetTemplate = tempSetTemplate.replaceAll("__label__", pro[j]);
tempSetTemplate = tempSetTemplate.replaceAll("__value__", Double.toString(proform[i][j]));
setList.add(tempSetTemplate);
}
for (String s : setList) {
line.append(s);
}
dataSetXml = "<dataset seriesname=\""+seriesname+"\">";
dataSetXml+=line.toString();
dataSetXml+="</dataset>";
}

return dataSetXml;
}
%>
<% String[] year={" "};
year = request.getParameterValues("year");
Show sh=new Show();

String pro[]={"一月","二月","三月","四月","五月"};
double proform[][]=new double [4][5];
for(int i=0;i<proform.length;i++)
{ for(int j=0;j<proform[i].length;j++)
{proform[i][j]=0;}
}
if( year ==null){}
else{
for(int i=0;i< year.length;i++){
String tmp=year[i];
List <axmt620> axmt=sh.Getaxmt620line(tmp);//確定能抓出數據並加總,但卻無法畫出第二條線.....
double tax=0;

for(axmt620 num: axmt)
{ tax=num.getOGB14().doubleValue()*num.getOGA24().doubleValue();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date= sdf.format(num.getOGA02()).substring(5,7);

switch (date) {
case "01":
proform[i][0]+=tax;
break;
case "02":
proform[i][1]+=tax;
break;
case "03":
proform[i][2]+=tax;
break;
case "04":
proform[i][3]+=tax;
break;
default:
proform[i][4]+=tax;
break;
}

}

}
}
String years[]= request.getParameterValues("year");

String categories = "<categories> ";
for (int i = 0; i < pro.length-1; i++) {
categories = categories + "<category label=\"" + pro[i] + "\" />";
}
categories = categories + "</categories> ";


if(years!=null && years.length>0){
String chartXML = "<chart> " + categories + " __allDataSet__ </chart>";

List<String> dataSetList = new ArrayList<String>();
for(String y:years){
String dataSet = createDataSetXml(y,pro,years,proform);
dataSetList.add(dataSet);
}
String allDataSetXml="";
for(String dataSet :dataSetList){
allDataSetXml+=dataSet;
}

chartXML = chartXML.replaceAll("__allDataSet__", allDataSetXml);
FusionCharts columnChart = new FusionCharts("msline", // chartType
"chart1", // chartId
"800", "500", // chartWidth, chartHeight
"chart", // chartContainer
"xml", // dataFormat
chartXML//dataSource
);
out.write(columnChart.render());
}
%>
[/code]
本篇文章回覆於2018-05-08 11:36
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
13樓
作者回應

黑~~
檢舉此回應
Silent 大大好:
我解出來了,不過是用一微陣列
算完一個年度後將陣列值歸0,在算下一個年度
想問大大,如果我想用2微陣列的話行不行得通
還是依定要用一為陣列呢?
謝謝
本篇文章回覆於2018-05-08 17:45
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
14樓
回應

Silent
檢舉此回應
可以 但是不好管理 也不好閱讀
你可以用物件的方式 每一條線 就是一個物件反而會比較簡單

public class LineData{

private Type data;

public LineData(Type data){
this.data = data;
}

public String getDataSetXml(){
return "xml format";
}

}


這是大概的樣子 我不知道你從資料庫抓的資料是甚麼樣子 沒辦法幫你設計
本篇文章回覆於2018-05-08 20:52
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
15樓
作者回應

黑~~
檢舉此回應
Silent 大大謝謝
我會往你說的方向再試試看的
本篇文章回覆於2018-05-09 10:59
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.