score:2
Accepted answer
Let's make your method simpler while we're fixing it. If you ever find yourself with code like this:
foo = []
bar.each{ … foo << jim }
…then instead you should be using this:
foo = bar.map{ … jim }
You have Date.UTC
in your Ruby code, which requires Ruby to run this code while building the array. Instead of creating an array of arrays, we'll use Enumerable#map
to convert your codes_by_user
into an array of strings that are the JS code that you want:
def byusers_chart_series(name, byusers)
codes_by_user = byusers.where(:hpmuser => "#{name}").group("date(hpmcreated)").select("date(hpmcreated) as dater, count(globalcode) as codes")
codes_by_user.map do |record|
parts = %w[year month day].map{ |s| record.dater.send(s) }
"[Date.UTC(#{parts.join(',')}),#{record.codes}]"
end
end
And then in your view:
data: [ <%= byusers_chart_series(name, byusers).join(", ") %> ],
This will produce output like the following in your HTML:
data: [ [Date.UTC(2011,10,7),42], [Date.UTC(2012,4,3),17] ],
Source: stackoverflow.com
Related Query
- How can I pass this array to a javascript function in an html.erb file, without erb evaluating the Date.UTC?
- How can I read an Excel File with JavaScript (without ActiveXObject)
- How would I convert this array to usable javascript array?
- Basic Javascript: How can I link my HTML and Javascript on a Highcharts example?
- How can I embed the AJAX output of JS in Javascript function
- How to pass this three inputs (lineEdit, startDate, endDate) to my function (graphdata)
- How to pass JSP array to Javascript of highchart to generate a column chart
- HighCharts is undefined because multiple Html pages in Javascript file
- How to Export JavaScript Chart to Excel file (HighCharts)
- How can I extend the lines of this Highchart series to the edges of my chart area?
- How to convert a JavaScript object to array
- JavaScript code inside TypeScript file .ts not working
- How do I pass in parameters to the Highcharts pointFormatter callback function
- c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page"
- How Can I Hide a Pie Chart's Slice in HighCharts Without Removing It From the Legend?
- how to display 2 same highcharts without duplicate the code
- How to access angular scope variable in JavaScript file
- How I can customize the file name when exporting using the plug-in CSV in Highcharts?
- Highcharts how to pass milliseconds to pointStart (really a javascript question)
- Javascript - How to display a specific index of an array on Highcharts?
- How can I pass values from Highcharts event callbacks (click, mouseOver, mouseOut) back to React component member function?
- how to add items to an array dynamically in javascript
- How can I put the Highchart to the html page
- How to update a Javascript object with a function
- HighCharts and Javascript to pass data as array
- How would I convert this array to this json format
- How to create dynamic array fo array in javascript
- How to pass array in highchart ??
- How can I show all Timeline Highcharts data without any overlapping?
- How can I unescape and remove quot; from data served by rails into javascript
More Query from same tag
- Use variable radius from HighCharts
- How to proceed only after all onClick events finished?
- Highcharts Modify Tooltip for One Series
- Jquery & Ajax for data retrieval used for highcharts implementation + HTML
- printing pie's dataLabels numbers with commas
- How to change Highchart tooltip font family
- Highchart plotLines z Index between series z Index
- Highcharts: Using JS arrays to populate series and x-axis categories
- Highcharts Gauge Spacing
- Variable tick length in highcharts
- angular2-chartjs/chartjs-plugin-annotation update options only one time
- Highcharts-vue fails to update data/series
- Datatime from CSV file to plot in Highstock JS error
- Multi-Line Title is not working when we export to PNG using CanVG - Highcharts
- MonthPicker in Highcharts Stockchart not changing month
- Highcharts, multiple parts chart
- Highchart pie legend circles
- HIGHCHARTS: Filling area above line with color area representing contribution to line values
- Highcharts 3D Pie color rendering
- How to change size of bubbles in Highcharts' 3D scatter chart?
- Highcharts tooltip date format when using pointFormat
- Change the color of legend symbol highchart
- How to add custom icons as markers in Highcharts
- get yAxis labels as 10% of the categories of xAxis
- Adding symbols and annotations to Highchart date axis
- Meteor + React + Highchart
- rCharts: Highcharts - how to flip coordinates for bar chart?
- Repeat labels in each x position on polar graph
- Highcharts, Rails - way to set start point for graph?
- Highchart with straight lines and empty circle bullet