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 Articles
- How can I pass this array to a javascript function in an html.erb file, without erb evaluating the Date.UTC?
- HighCharts is undefined because multiple Html pages in Javascript file
- JavaScript code inside TypeScript file .ts not working
- c# WPF Webbrowser with Highchart, Javascript from external source not working "An error has occurred in the script on this page"
- How would I convert this array to usable javascript array?
- HighCharts and Javascript to pass data as array
- Javascript Highcharts: series datalabel formatter function to loop data not formatting all data form the array
- HTML Content to Javascript Code
- Unable to refer javascript array from another javascript file
- Pass vales from Javascript back to C# function
- How to pass this three inputs (lineEdit, startDate, endDate) to my function (graphdata)
- Pass PHP result-set to JavaScript array in Highchart?
- How to pass JSP array to Javascript of highchart to generate a column chart
- JavaScript - Export Div with SVG chart + HTML as and Image
- How can I read an Excel File with JavaScript (without ActiveXObject)
- Optimize JavaScript DrillDown code
- DB Array to expected javascript format
- How to Export JavaScript Chart to Excel file (HighCharts)
- Dynamic PDF from html that contains Javascript
- Pass Data String as parameter to a Function for HighCharts
- Pass function to jquery from php
- How to convert a JavaScript object to array
- Passing a JavaScript function from JSON encoded PHP
- To pass dynamic json array to Highcharts Pie Chart
- Add Local HTML and JS file using React Native Webview
- How do I pass in parameters to the Highcharts pointFormatter callback function
- Sending javascript function with JSON is possible?
- how to display 2 same highcharts without duplicate the code
- Issue while passing array to setData() function
- How to access angular scope variable in JavaScript file
- MultiBarChart with HighCharter in shiny app
- High Charts: Change each individual plot/marker size, is it possible?
- Show checkboxes within diagram legend does not work well if scrollablePlotArea is configured
- Highcharts pie labels outline mising using styled mode
- Highcharts distorsion
- Highmaps: how to disable map zoom by mouse scroll
- Highcharts axis does not show properly values when numbers are so small
- Multiple series in Highcharts with multiple drilldowns
- Highcharts shared tooltip positioning if single value only
- Highcharts Org chart children links are overlapping
- 3 level Drilldown of a column chart in highchart?
- Highcharts tooltip not showing on chrome
- Negative and positive in same direction in highchart
- Handle touch event on Apple - Highcharts
- remove series by name or id in highcharts
- Highcharts - format date for x-axis as well as autoscale (data from mysql)
- Object [object Object] has no method 'highcharts'
- JQuery UI Slider in Highcharts using more then one datapoint
- Highcharts yAxis labels inside plot area and left padding
- How to force points above maximum to be on maximum grid line, but still show real value in tooltip