我試圖在EXTJS 3窗口中使用Highcharts繪製一些數據。 使用固定的數據數組,一切正常,但我需要繪製從python cgi獲取的數據,該數據返回json。 這是Python CGI如何創造我的數據(切片,我跳到數據庫的連接等):ExtJS 3和Highcharts,JsonStore加載數據時出現問題
query = "select timestamp, value from "+measure_table+" where id_resource = 280 and timestamp < '2011-07-13 03:59:00'"
#execute the query
cur.execute(query)
rows = cur.fetchall()
#create the empty json data rpeository to be filled in
json_root = { 'fields': ['timestamp', 'value'], 'data':[] }
for row in rows:
json_root['data'].append({'timestamp':str(row[0]), 'value':row[1]})
#spit out the json and we are done!
req.write(str(json_root))
而且這是在我嘗試加載該數據的JS:
var jproxy = new Ext.data.HttpProxy({
url: 'the url where to find the cgi'
});
var jstore = new Ext.data.Store({
proxy: jproxy,
reader: new Ext.data.JsonReader({
idProperty: 'timestamp',
root: 'data',
fields: [
{name: 'timestamp', mapping: 'timestamp'},
{name: 'value', mapping: 'value'},
]
})
});
然後我創建窗口和圖表。 現在有兩個問題:第一個很簡單:這段代碼有什麼問題?螢火控制檯說:
Ø未定義
如果(o.metaData){
在EXT-ALL-debug.js的26042線,調試腳本我的一個包含在我的html頭文件中。 該窗口已創建,但當然沒有圖表。這是哪種錯誤?如果我評論一個大/ * .... * /創建代理和商店錯誤消失,所以問題應該在那裏。 編輯:我已經修復了這個問題,我用不正確的函數加載了商店..我使用的是jstore.loadData()而不是jstore.load(),我的錯誤..我的故障。
第二個問題是:這是(下面的代碼)正確的方式來從jsonstore圖表與高圖的數據? (我們是圖表創建中,我不張貼整個代碼「因爲它的工作原理,也許它不是有用的張貼)任何答案
xField: 'timestamp',
store: jstore,
series: [{
yField: 'value'
}]
}
很多很多的感謝!
編輯:後我固定數據的加載新的問題:
too much recursion
jqextend(),DanaI...xtjs.js (riga 81)
merge(),DanaI...xtjs.js (riga 92)
Chart(),DanaI....src.js (riga 3922)
options = Object { chart={...}, title={...}, altri elementi...}
callback = undefined
draw(),DanaI...hart.js (riga 229)
call(),DanaI...ebug.js (riga 1547)
, copy);
這是Firebug的控制檯output..too的遞歸?哪個遞歸?我沒有在我的代碼中使用任何遞歸函數..
由python cgi給出的json是正確的,我在另一個應用程序(網格)中使用它,一切工作正常..(我也使用相同的代理和存儲,所以我無法弄清楚是什麼問題。 ) – powder
你應該在任何情況下使用json/simplejson,因爲在非常簡單的情況下''dict .__ str__''會產生無效的JSON(例如,如果值爲None)。不知道highcharts問題,我只使用JavaScript文字自己加載數據。 – codeape
好的,無論如何,我會閱讀關於json的一些文檔 – powder