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 Articles
- Complicated Rails query for reports with missing data
- Show gap of missing data with Highstock
- Highcharts - Global configuration with common code and unique data & Headings
- Sql query to populate 0's for missing data
- How to input plot data into highcharts with rails
- Rails Memory leak using highChart with a lot of data
- Plot Highcharts data from past 30 days with Ruby on Rails
- Have an issue with JavaScript, AJAX code displaying data
- Highcharts Synchronized charts with missing data points
- Highcharts series visibility with csv data source
- How to have multiple highcharts with different series data in vuejs without repeating code
- High Charts Line Chart with missing data
- Highcharts multiple series with missing Data Points
- Highcharts cloud issue with data source when duplicating chart
- Rails + PostgreSQL group data hourly with datetime
- Highcharts displays series names but missing data points from json source
- How to make highcharts default to 0 for missing data
- Reload chart data via JSON with Highcharts
- Resize data points with highcharts
- Highcharts doesn't display series with lots of data points
- Highcharts data series issue with ajax/json and PHP
- creating highchart with ajax json data
- Highcharts - Dyanmic graph with no initial data
- Automatically join missing data gaps in Highcharts JS
- Load data into Highcharts with Ajax
- Plot Highchart Gauge with JSON Data
- HighChart Heatmap with JSON data
- Highcharts custom visuals with Data binding PowerBI
- How to display highchart y axis with constistant data
- Updating data in charts, highcharts with angular, highcharts-ng
- Highcharts showing wrong time based on timezone
- Show Highcharts tooltip at the bottom of the chart in responsive mobile version
- does Highstock support a right border for a panel (yAxis)?
- How To Show All Data Labels For Datetime Axis In Highcharts
- How disable the 'k' dislay in Highcharts ordinate?
- Highstock Chart with URL in flag text won't open in new window
- Issues in Data Label
- How to get points information when hovering over axis labels in highcharts using custom-events library?
- Heatmap series name doesnt show up
- Display Percentage Values on Z-axis (highcharts) bubble chart
- highcharts - Hide some labels in yAxis
- Saving 30 keys from an array to another variable
- High Charts - Split color of bar chart
- CSS Style not getting applied to a series in Highchart
- HighCharts, multiple charts on page call via function
- How can I stop HighCharts drawing an extra 'tick' outside the graph area?
- How do I get Highmaps zoom level and is there a Highmaps zoom event?
- Check if all legend items are selected in highcharts?
- Remove padding from HighCharts polar chart
- Export json data with highcharts