0

I´m trying to make this column graph stacked:

<%= column_chart  [
              {name: "Paper", data: current_user.papers.map{|t| [t.paper_type, t.paper_weight] }, 'interpolateNulls':true, 'stacked':true},
              {name: "EnvPaper", data: current_user.papers.map{|t| [t.paper_type, t.env_paper_weight ] }, 'interpolateNulls':true, 'stacked':true} ] %>

I read in the chartkicks documentation that this bit of code could make it stacked

<%= column_chart data, stacked: true %>

so I tried couple of modifications but nothing seems to work. Now my graph code looks like this.

<%= column_chart data, stacked: true, current_user.papers.map{|t|
              {name: t.paper_type, data: t.paper_weight.count, t.env_paper_weight.count }} %>

and it gives me this error :

syntax error, unexpected '}', expecting =>
...unt, t.env_paper_weight.count }} );@output_buffer.safe_appen...
...                               ^
/Users/dadi/Documents/Vefir/SprettaEMS1.5/app/views/users/show.html.erb:115: syntax error, unexpected keyword_ensure, expecting '}'
/Users/dadi/Documents/Vefir/SprettaEMS1.5/app/views/users/show.html.erb:117: syntax error, unexpected keyword_end, expecting '}'

I´m really stuck here, is anyone here that can help me?

thanks in advance Dadi

DaudiHell
  • 808
  • 10
  • 32

1 Answers1

1

You have added the code in the wrong place, try it like this:

<%= column_chart stacked: true, data: current_user.papers.map{|t|
          {name: t.paper_type, data: t.paper_weight.count, t.env_paper_weight.count }} %>
Uri Agassi
  • 36,848
  • 14
  • 76
  • 93
  • Hi I´m sorry but there is no luck with this version either, it still gives me the error: `syntax error, unexpected '}', expecting => ...unt, t.env_paper_weight.count }} );@output_buffer.safe_appen...` – DaudiHell Mar 07 '16 at 15:07
  • I also tried the link that Uday recomented in his answer, but there was no luck with that one. – DaudiHell Mar 07 '16 at 15:09
  • 1
    @DaðiHall I'm pretty sure you did not copy my code exactly. The error you are experiencing is because you should pass a hash (key-value pairs), in the form of `key1: value1, key2: value2`... (or `key1 => value1`). Your code looks like `key1, key2: value2, value1`, which confuses the parser. Please check your code again. – Uri Agassi Mar 07 '16 at 18:46
  • I came down to solving this problem like this ` <%= column_chart [ {name: "Paper #{current_user.profile.name}", data: current_user.papers.group_by_year(:created_at).sum(:paper_weight)}, {name: "Paper all Avr", data: Paper.group_by_year(:created_at).average(:paper_weight)}], { stacked: true, height: "250px"} %>`this works fine. I´ll give your code another run when I have time. Thank you for your responce – DaudiHell Mar 07 '16 at 19:46