Skip to content

Instantly share code, notes, and snippets.

@cesswairimu
Created January 14, 2019 10:22
Show Gist options
  • Save cesswairimu/91b091302ab959c4a4f735e8a03e94c0 to your computer and use it in GitHub Desktop.
Save cesswairimu/91b091302ab959c4a4f735e8a03e94c0 to your computer and use it in GitHub Desktop.
// trying to use this function to plot my values
helpful link => https://codepen.io/apexcharts/pen/QrbEQg
function generateDayWiseTimeSeries(s, count) {
var values = [[
<%= @graph_notes.values.collect {|ind| ind[1]} %>,
<%= @graph_wikis.values.collect {|ind| ind[1]} %>,
<%= @graph_comments.values.collect {|ind| ind[1]} %>
]];
var i = 0;
var series = [];
var x = new Date("11 Nov 2012").getTime();
while (i < count) {
series.push([x, values[s][i]]);
x += 86400000;
i++;
}
return series;
//first I want value x to be something like <%= @time %>
//also I cannot get what line 16 is doing.
@Harrisonkamau
Copy link

line #16 converts new Date() to unix time.

@cesswairimu
Copy link
Author

so I have an instance var @time from rails controller and I want to use it instead...ps..the script is on a template

@Harrisonkamau
Copy link

Leave a comment here, if you need further assistance. I'll refresh this gist in a few minutes :)

@Harrisonkamau
Copy link

Oh, I see:

You want to assign @time to x?

@cesswairimu
Copy link
Author

yeah...e.g of time January 14, 2019 13:04

@Harrisonkamau
Copy link

I think the conversion has already been done on line #16, so my guess you're trying to overwrite the @time instance variable?

@Harrisonkamau
Copy link

Though that appears to be a

yeah...e.g of time January 14, 2019 13:04

This is not a unix time, I think it's UTC, so line #16 should be removed

@Harrisonkamau
Copy link

Quick question: if you're getting the date from Rails, why are you redefined the date on line #13?

@cesswairimu
Copy link
Author

and replace with?

@cesswairimu
Copy link
Author

time changes according to the input selected so it should not be constant

@Harrisonkamau
Copy link

I'm guessing the script you sent me is a .js?

If so, then you could create a helper function that converts the date from Rails to a UTC date

@Harrisonkamau
Copy link

But as long as you're getting it from the Rails (API), you don't have to worry since the API is already validating the type of input

@Harrisonkamau
Copy link

Or maybe I'm not really getting you :'(

@cesswairimu
Copy link
Author

and then how will js consume it?

@cesswairimu
Copy link
Author

waiting for the link

@Harrisonkamau
Copy link

@Harrisonkamau
Copy link

There you go

@Harrisonkamau
Copy link

<script>
console.log('Hello world');
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment