2011-07-28 37 views
0

我需要爲我的trac插件可視化數據。因此,我想使用Open Flash Charts 2. 嘗試按照this未按預期工作。如何用OFC Python繪製圖表?

問題

的Chartdata不會顯示,唯一的輸出是加載動畫由OFC。 本教程中的所有內容都與html源代碼非常相似。

如何將JSON數據加載到我的圖表中?

其他信息

我寫的,其中處理的數據應該進入了一個模板。

CHART_TEMPLATE = Template(
       ''' 
       <script type=\"text/javascript\" src=\"$json_path/json2.js\"> 
       </script> 
       <script type=\"text/javascript\" src=\"$js_path/swfobject.js\"> 
       </script> 
       <script type=\"text/javascript\"> 
       swfobject.embedSWF(\"$ofc_path/open-flash-chart.swf\", 
\"$chartname\", \"$width\", \"$height\", \"9.0.0\"); 

       function open_flash_chart_data() 
       { 
       alert('reading data'); 
       return JSON.stringify($json_chart_data); 
       } 

       function ofc_ready() 
       { 
       alert('ofc_ready'); 
       } 
       </script> 

       <div id=\"$chartname\"></div> 
       ''' 
      ) 

數據轉換爲JSON與Open Flash Charts python,這似乎工作得很好。

def chartdata_from_timetable(self, dict, title): 
    ''' 
    creates chartdata in JSON-format from 2 dim dictionary 

    ''' 
    elements = [] 
    x_labels = [] 
    dc = DateConversion.DateConversion() 
    # if startdate on a weekend, startdate might 
    not be inluced in the dict->  
    choose next monday 
    for key in timetable[startdate]: 
     element = Chart() 
     element.type = "line" 
     element.text = key 
     values = [] 
     for date in dict: 
      values.append(dict[date][key]) 
      x_labels.append(string_from_date(date)) 
     element.values = values 
     elements.append(element) 
    chart = Chart() 
    chart.x_axis.labels = x_labels 
    chart.title.text = title 
    chart.elements = elements 
    return chart.create().encode() 

此後以下數據返回,沒有一個似乎缺少:

CHART_TEMPLATE.safe_substitute(js_path = config['js_dir'],..., 
json_chart_data = chart_data) 

回答

0

你必須檢查ofc文件夾的trac.ini的路徑是正確的。
函數chartdata_from_timetable也是不對的。由於覆蓋,您只能看到最後一個條目的值。