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
- Nanosecond plots using highstockJS
- How do I put Icons in the y Axis for a Dynamic Highcharts chart?
- Extend line until new value occurs
- How to dynamically load highcharts
- Where can I find the type definition of the Highcharts.AnnotationsOptions type?
- Highchart: Only show one series at a time
- Changing backgroundcolor of tooltip for a specific data point in Highcharts
- adapting text to highchart tooltip max width
- HighCharts Heatmap yAxis title
- Jumping on the x axis in Highcharts
- In a Highchart, how to display the legend text in next row if the text is too long?
- how to change the width between columns ? HIGHCHARTS
- High charts, providing data for xAxis instead of Series
- Update in HighCharts in Yii
- Effective way to display the data in the chart
- Highcharts - Resizeable y-axis as one for Candlestick & Volume chart
- How to bind dynamic data in highcharts Tooltip
- Can't change xaxis in highcharts
- highcharts hover with negativeColor property gives wrong color
- Highcharts add button fix chart
- How to get index of a point in Highcharts?
- highchart editor library event listening
- In HighMaps how can we pattern fill a world map?
- Highcharts date time axis
- Highcharts Percentile Distribution Graph issue
- Highcharts: Marker radius does not seem to work
- Highcharts bar grouping while maintaining transparent overlay?
- Prevent Highchart.js from cutting xAxis label
- problem with highcharts series option
- Bars inside highchart is overlapping when exported to PDF