2013-10-31 145 views
0

我的flot圖表不顯示任何行,使用Integer在Java中將紀元乘以1000時出現問題?
這是我的原始數據,保存在一個.txt文件Java,將紀元時間轉換爲毫秒

epoch,value 
1383229104,55559 
1383229121,55559 
1383229787,55565 

這是由一個Servlet解析,並保存在裏面:

Vector<Integer> points = new Vector<Integer>(); 

points.add(Integer.parseInt(strLine.split(",")[0]) * 1000); 
points.add(Integer.parseInt(strLine.split(",")[1])); 

有多個文件,每一個都包含一個單獨的系列(線)在圖上繪製。
對於每個Vector<Integer> points對象,它們被添加到..

Vector<Dataset> datasets = new Vector<Dataset>(); 

數據集有如下定義:

public class Dataset { 

    private String name; 
    private Vector<Vector<Integer>> points; 

一旦所有的文件都被解析並添加到Vector<Dataset> datasets,這個對象發送客戶端使用response.getWriter().write(new Gson().toJson(datasets));
和 '繪製' 使用

var datasets = JSON.parse(xmlhttp.responseText); 

    var plotarea = $("#placeholder"); 
    $.plot(plotarea, [datasets[0].points, datasets[1].points, datasets[2].points, datasets[3].points, datasets[4].points], { 
     xaxis: { 
      mode: "time", 
      min: (new Date(2012, 0, 1)).getTime(), 
      max: (new Date(2015, 0, 1)).getTime() 
     } 
    }); 

更新: --------------------------------------------- -----------------------------
在javascript中調試輸出。
有5個文件被加載到Vector<Dataset> datasets = new Vector<Dataset>();

alert(datasets) .. [object Object],[object Object],[object Object],[object Object],[object Object] 
console.log(datasets) .. [object Array] 

我可以使用訪問值:

alert(datasets[0].points[0][0]); 
alert(datasets[0].points[0][1]); 

輸出將是兩個警報對話框,一種含249634688,第二55559
注:1383229104 * 1000不應該是249634688

+0

,你能否告訴我們的'的console.log(數據集)'輸出? – Mark

+0

更新後的描述與'console.log(datasets)'和'alert(datasets)'輸出的更新描述' – bobbyrne01

回答

0

更改private Vector<Vector<Integer>> points;private Vector<Vector<Long>> points;
引起預期的結果即1383229104000

+0

您可以從問題中看到'alert(datasets [0] .points [0] [0]);'output'249634688'因爲紀元被倍增1000,並存儲在一個不能處理這麼大值的Integer對象中。 – bobbyrne01

2

你應該使用Long而不是Integer。顯然這是一個溢出問題。