score:1
well, for starters, you can simplify your code for the same basic approach with the following:
when 'likely1-5'
(1..5).each do |k|
v = stats[k.to_s] || 0
report_collection.push(v.to_i)
end
score:1
let's see if this works.
question_id = xxx
stats = responseitem.select('score, count(id) as count').
where(question_id: question_id).
joins('right outer join (select "1" as score union select "2" union select "3" union select "4" union select "5") as scores on score = answer_text').
group('score')
scale = stats.reduce({}) do |memo, answer_count|
memo.merge(answer_count.score.to_i => answer_count.count)
end
Source: stackoverflow.com
Related Query
- Complicated Rails query for reports with missing data
- Sql query to populate 0's for missing data
- How to make highcharts default to 0 for missing data
- Show gap of missing data with Highstock
- Rails ActiveRecord group_by & sum db results for use with Lazy HighCharts
- Advanced LINQ Grouping and Projection Query for Hierarchical Data (EF 4.0 + LINQ + ASP.NET MVC + HighCharts)
- Alternatives to Highcharts for datasets with 10k data points?
- Highcharts - Global configuration with common code and unique data & Headings
- Highcharts not displaying series data for graph with multiple Y-axes
- Formatting JSON Data with ColdFusion for HighCharts
- AngularJS for Highcharts with dynamic ajax data
- Data with timestamp group to month(like Jan, Feb, March) and showing as total count for month in Highcharts
- Highcharts: make y-axis extremes the same for two data series with different units
- Set zero for missing data in highcharts
- Splitted bar chart for paired data with highcharts
- How to input plot data into highcharts with rails
- HighChart Sparkline Chart with dynamic data for the table
- Rails Memory leak using highChart with a lot of data
- Retrieving JSON data for Highcharts with multiple series?
- Pie Chart for Data on Different Things with HighChart
- Highchart with Range selector for SQL Data in html website
- highcharts example for using data from database with mvc
- Plot Highcharts data from past 30 days with Ruby on Rails
- Have an issue with JavaScript, AJAX code displaying data
- Output query data in other format for chart to recognize
- Highcharts display label for pie chart using html table as data source
- Extract data series from a JSON array for a Highcharts chart with 2 y-axis
- Highcharts Sparkline chart with dynamic data for table -Angular js
- Data labels with "callout" shape misses pointing triangle for short text
- Two DataSeries for yAxis 1 and 2 with Data from SQLdb
More Query from same tag
- One label for multiple series
- Hichcharts (Highstock) — Why isn't the plotLine being drawn on the chart?
- plot bands in x-axis is not working on time
- Enabling scroll bar on y-axis of the high charts heatmap showing up some additional y-axis labels
- Among Fusion Charts,High Charts,EXTJs Charts better
- Export multiple series from highcharts into CSV
- Highchart highstock startOnTick Error
- highcharter: BoxPlot Outliers not being on correct x-axis point
- Highcharts -> how to add vertical title to bar? how to make the symbol in the legend a rectangle?
- Highcharts not rendering plotbands correctly on first load
- Add text over export button in Highcharts
- How to hide color axis in heatmaps using highcharts
- Highchart, bar chart with multiple series
- Highstock - change tickpositioner dynamically
- How to make highcharts funnel into pyramid
- change the categories and series in highcharts by select button?
- highcharts via json how to get the xAxis?
- Highchart guage needles showing below data labels
- Filename not assigned to csv export in HighCharts on Mac
- Highstock title and subtitle overlap
- How would I fill a table from highchart data?
- highcharts stockchart tooltip on flags switches to data series tooltip while mouse is still over flag
- Angular HighChart in tabs width
- Issue with last column width in Highcharts
- Selenium: How to relate an id or a class to a specific div?
- Draw JSON result in highchart
- How to position the customed tootip of HighCharts?
- how to disable the color change on mousehover in sankeycharts Highchart . { hover: {color: '#a4edba',opacity: 1,filter: {type: 'none',}}} didnt work
- How to display HighCharts with tables
- I had created a scatterplot using Highcharts but the the point.z value is not getting displayed in tooltip