0

現在、Ruby on Rails アプリを作成しており、lazy high charts gem を使用していくつかのグラフを表示しています。ただし、1 ページに 2 つのグラフを表示するのに問題があります。後者のグラフが最初のグラフを上書きしているように見えるため、表示されるのは 2 番目のグラフだけです。別々に置くと両方のグラフが表示されます。両方のグラフを 1 ページに表示するにはどうすればよいですか?

これは私のコントローラーにあるものです

@performance_chart = LazyHighCharts::HighChart.new('graph') do |f|
  f.title(:text => "Team Performance")
  f.xAxis(:categories => @x_axis)

  f.series(:name => @team.name, :yAxis => 0, :data => @performance)
  f.series(:name => "Top Scores for " + @team.division.name.capitalize[0...-1] + " Division", :yAxis => 0, :data => @top_scores)
  f.series(:name => "Averaged Scores for "+ @team.division.name.capitalize[0...-1] + " Division", :yAxis => 0, :data => @average_scores)
  f.yAxis [
    {:title => {:text => "Quiz Scores", :margin => 70} }
  ]
  f.chart({:defaultSeriesType=>"line"})
end 

#bar graph for individual team members 
@member_chart = LazyHighCharts::HighChart.new('column') do |f|
  f.title(:text => "Population vs GDP For 5 Big Countries [2009]")
  f.xAxis(:categories => ["United States", "Japan", "China", "Germany", "France"])
  f.series(:name => "GDP in Billions", :yAxis => 0, :data => [14119, 5068, 4985, 3339, 2656])
  f.series(:name => "Population in Millions", :yAxis => 1, :data => [310, 127, 1340, 81, 65])

  f.yAxis [
    {:title => {:text => "GDP in Billions", :margin => 70} },
    {:title => {:text => "Population in Millions"}, :opposite => true},
  ]

  f.legend(:align => 'right', :verticalAlign => 'top', :y => 75, :x => -50, :layout => 'vertical',)
  f.chart({:defaultSeriesType=>"column"})
end

これが私の見解です

<div = class"row">
    <div class="card">
        <%= high_chart("some_id", @performance_chart) %>
    </div>
</div>  

<div class="row">
    <div class="card">
        <%= high_chart("some_id", @member_chart) %> 
    </div>
</div>
4

1 に答える 1

2

HighChart.new() は 3 つのパラメーターを取り、そのうちの 1 つは div タグの作成に使用されることがわかりました。

 def high_chart(placeholder, object, &block)
  object.html_options.merge!({:id => placeholder})
  object.options[:chart][:renderTo] = placeholder
  high_graph(placeholder, object, &block).concat(content_tag("div", "", object.html_options))
end

そのため、コントローラーから呼び出した、表示されたグラフの 1 つの ID の名前を変更するだけで済みました。そうでない場合は、同じ id を持つ div タグ (私の場合は作成した最初のグラフ) を見つけて、以前に表示されたグラフを置き換えます。問題を解決するために、私は変更しました

<%= high_chart("some_id", @member_chart) %> 

<%= high_chart("some_other_id", @member_chart) %>
于 2015-06-08T20:54:44.827 に答える