papakay
September 25, 2017, 12:23pm
1
I have an enumerable data as below
["Mar 2017", "Apr 2017", "May 2017", "Jun 2017", "Jul 2017", "Aug 2017",
"Sep 2017", "Oct 2017", "Nov 2017", "Dec 2017", "Jan 2018", "Feb 2018"]
intended to be passed to highchart x-axis data.
When i passed the data to using <%= chart_label %>
I keep getting
Mar 2017Apr 2017May 2017Jun 2017Jul 2017Aug 2017Sep 2017Oct 2017Nov 2017Dec 2017Jan 2018Feb 2018
Please what is the best way to achieve this?
Thank you.
papakay
September 25, 2017, 12:41pm
3
I tried it but was returning
["Mar 2017", "Apr 2017", "May 2017", "Jun 2017", "Jul 2017", "Aug 2017", "Sep 2017", "Oct 2017", "Nov 2017", "Dec 2017", "Jan 2018", "Feb 2018"]
Is there any approach to have the quote instead of "?
If you’re using Phoenix Framework, the phoenix_html
library has a nice function called raw/1
that won’t escape it.
1 Like
papakay
September 25, 2017, 1:01pm
5
I have tried raw initially but the result was below
Mar 2017Apr 2017May 2017Jun 2017Jul 2017Aug 2017Sep 2017Oct 2017Nov 2017Dec 2017Jan 2018Feb 2018
with no quote.
papakay
September 25, 2017, 1:06pm
6
Thanks so much.
I have tried adding raw to the inspect and it gave the required result.
<%= raw inspect(label) %>
Thank you for the pointer.
Please I observed that returning enum with integers converts the the items to a string.
["0", "0", "0", "0", "0", "0", "808500", "0", "0", "0", "0", "0"]
Is there a way to keep it as integer. Highcharts requires data as integer and not string.
inspect
is not really a good way to do this, because while it might work here, it will break at least as soon as you try to use dates somewhere in that data. The simple way would be to convert the data to json and output the json in your view.
1 Like
papakay
September 25, 2017, 1:12pm
8
Please can you give a me like a skeleton code to understand how to implement this. I currently compute the chart labels and data in the my view file.
papakay
September 25, 2017, 1:18pm
9
This was an error on my part. It’s showing fine now.
I do all of my Elixir data -> Javascript through JSON serialization, like so:
<script>
const label = JSON.parse("<%= label |> Poison.encode!() |> raw() %>")
</script>
It always works!
papakay
September 25, 2017, 8:12pm
11
Thanks so much for the wisdom shared. It worked well.