2013-11-28 27 views
1

我正在使用此multi-graph Dashing widget。它工作正常,但它只使用兩個數據系列,我想再添加一個。我修改了.coffee文件到人力車堆疊多圖

class Dashing.Mgraph extends Dashing.Widget 

    @accessor 'current', -> 
    return @get('displayedValue') if @get('displayedValue') 
    points = @get('points') 
    if points 
     points[0][points[0].length - 1].y + '/' + points[1][points[1].length - 1].y '/' + points[2][points[2].length - 1].y 

    ready: -> 
    container = $(@node).parent() 
    # Gross hacks. Let's fix this. 
    width = (Dashing.widget_base_dimensions[0] * container.data("sizex")) + Dashing.widget_margins[0] * 2 * (container.data("sizex") - 1) 
    height = (Dashing.widget_base_dimensions[1] * container.data("sizey")) 
    @graph = new Rickshaw.Graph(
     element: @node 
     width: width 
     height: height 
     renderer: 'area' 
     stroke: false 
     series: [ 
     { 
     color: "#fff", 
     data: [{x:0, y:0}] 
     }, 
     { 
      color: "#222", 
      data: [{x:0, y:0}] 
     }, 
     { 
      color: "#333", 
      data: [{x:0, y:0}] 
     } 
     ] 
    ) 

    @graph.series[0].data = @get('points') if @get('points') 

    x_axis = new Rickshaw.Graph.Axis.Time(graph: @graph) 
    y_axis = new Rickshaw.Graph.Axis.Y(graph: @graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT) 
    @graph.renderer.unstack = true 
    @graph.render() 

    onData: (data) -> 
    if @graph 
     @graph.series[0].data = data.points[0] 
     @graph.series[1].data = data.points[1] 
     @graph.series[2].data = data.points[2] 
     @graph.render() 

但是,當我運行dashing時,它沒有顯示任何東西(甚至沒有其他小部件)。這只是一個空白的屏幕。誰能告訴我這裏發生了什麼?

編輯:

我已經隔離了更多的問題。看來,一切工作,直到我在series:添加第三個數據系列似乎是這樣,導致它無法正常工作。

+0

不知道如果我的問題是不清楚的,或者沒有人知道答案... – user1893354

+1

只是想知道你是否碰巧把同樣的問題發佈到git hub上的多圖的所有者。 – sam

+0

不是所有者,但我將其發佈在github的github上。還沒有答案。我想我應該把它發佈在那裏,謝謝。 – user1893354

回答

2

在這裏,請嘗試使用rickshawgraph部件https://gist.github.com/jwalton/6614023

這裏是我的.rb

points1 = [] 
points2 = [] 
points3 = [] 
(1..10).each do |i| 
    points1 << { x: i, y: 10 } 
    points2 << { x: i, y: 10 } 
    points3 << { x: i, y: 10 } 
end 
last_x = points1.last[:x] 

SCHEDULER.every '2s' do 
    points1.shift 
    points2.shift 
    points3.shift 
    last_x += 1 
    points1 << { x: last_x, y: rand(50) } 
    points2 << { x: last_x, y: rand(10) } 
    points3 << { x: last_x, y: rand(100) } 

    series = [ 
     { 
      name: "set1", 
      data: points1 
     }, 
     { 
      name: "set2", 
      data: points2 
     }, 
     { 
      name: "set3", 
      data: points3 
     } 
     ] 
    send_event('convergence', series: series) 
end 

這裏是我的.erb

% content_for :title do %>My super sweet dashboard<% end %> 
<div class="gridster"> 
<ul> 
    <li data-row="1" data-col="1" data-sizex="2" data-sizey="1"> 
    <div data-id="convergence" data-view="Rickshawgraph" data-title="Convergence" data-unstack="true" data-stroke="true" data-default-alpha="0.5" data-color-scheme="compliment" data-legend="true" data-summary-method="last"></div> 
    </li> 
</ul> 
</div>