-1

I´m trying create a file for a FLOT chart with next data:

{
        'label': 'Clicks',
        'color': Colors.byName('purple-300'),
        data: [
        ['1', 40],
        ['2', 50],
        ['12', 135]]
}

How can I create the data section array in jBuilder?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
hazardco
  • 387
  • 1
  • 4
  • 13
  • 1
    Please show us what have you tried so far. – Aleksei Matiushkin May 04 '16 at 13:05
  • 1
    Welcome to SO. Please read "[ask]", including the links. We need to see your effort. Did you write code? If no, why not? If you did, tell us why it doesn't work, give us the minimum data to confirm the problem and your expected output. SO isn't a "write code for me site", it's a "help me fix my broken code" site. http://meta.stackoverflow.com/q/261592/128421 is applicable. – the Tin Man May 05 '16 at 00:03
  • sorry but my english is not good and I can hardly explain the problem. – hazardco May 05 '16 at 06:36

1 Answers1

1

i found a solution:

`json.label "Clicks"
 json.color "purple-300"
 json.data @direccion.analiticas.map{|i| ["#{i.id}",i.total_clicks]}`

Result:

`{"label":"Clicks","color":"purple-300","data":[["1",24],["2",20],["3",42],["4",10],["5",1],["6",14]]}`

It´s a good star. To pass this result to a graph Flot need the result is between square brackets [ ] and I can not find how to do this.

The result should be:

[{"label":"Clicks","color":"purple-300","data":[["1",24],["2",20],["3",42],["4",10],["5",1],["6",14]]}]

Thanks!

UPDATE

Final solution:

 json.array!(@direccion) do |direccion|
  json.label "Clicks"
  json.color "purple-300"
  json.data direccion.analiticas.map{|i| ["#{i.id}",i.total_clicks]}
end

Thanks for all.

hazardco
  • 387
  • 1
  • 4
  • 13