score:1
this is a highcharts specfic. you need to pass in the timestamp into your data array vs. defining it for the dataset.
for each data point, i set [time,value] as a tuple.
[ "date.utc(#{date.year}, #{date.month}, #{date.day})" , weight.pounds_on(date).to_f ]
you will still need to remove the zero's in w/e fashion you like, but the data will stay with the proper day value.
i do think you need to remove :pointinterval => 1.day
general tips
you should also, look at optimizing you query for pound_on, as you are doing a db call per each point on the chart. do a weight.where(:created_at => date_start..date_end ).group("date(created_at)").sum(:weight_input)
which will give you an array of the created_at dates with the sum for each day.
additions
improved sql query
this leans on sql to do what it does best. first, use where to par down the query to the records you want (in this case past 30 days). select the fields you need (created_at and weight_input). then start an inner join that runs a sub_query to group the records by day, selecting the max value of created_at. when they match, it kicks back the greatest (aka last entered) weight input for that given day.
@last_weight_per_day = weight.where(:created_at => 30.days.ago.beginning_of_day..time.now.end_of_day)
select("weights.created_at , weights.weight_input").
joins("
inner join (
select weights.weight_input, max(weights.created_at) as max_date
from weights
group by weights.weight_input , date(weights.created_at)
) weights_dates on weights.created_at = weights_dates.max_date
")
with this you should be able @last_weight_per_day
like so. this should not have 0 / nil values assuming you have validated them in your db. and should be pretty quick at it too.
@pounds = @last_weight_per_day.map{|date| date.weight_input.to_f}
Source: stackoverflow.com
Related Query
- Rails App Plotting Zeros in Highchart Graph via Lazy_High_Charts Gem
- gem Lazy High Charts - Pie Donut
- High Charts Breaking jQuery Across Rails App
- High charts remove dots from the line graph
- High Charts - mouse over event on any part of graph
- Nested table yields unexpected columns for a basic column graph using high charts with 'Data defined in a HTML table'
- Not able to render the charts in pdf using Wickedpdf and Highcharts in rails 2.3 app
- Why is Highchart loaded twice in my rails app ? (Uncaught Highcharts error #16)
- Can we Fixed High charts graph portion height irrespective of number of series or legends?
- How to create a drilleable bar graph in jsp page using open source charts API
- Displaying multiple graphs on one page using lazy high charts
- How to remove a gap in high charts graph with two yAxis
- How Do I put Multiple Charts on the Same Graph rCharts High Charts
- MACD + High chart Graph plotting issue
- High Charts Graph insert into PDF using FPDF library
- high charts - how do I get a stacked graph to the full width?
- Highchart graph not plotting - CSV
- lazy high charts rails, what is "my_id" ? in <%= high_chart("my_id4", @chart) %>
- high charts line graph x-axis issue
- I want to add border radius in stack graph in high charts for some particular data
- Highchart graph not displaying via Django
- How to show bar of graph in different colour when it reaches threshold level in high charts in JS?
- High charts bar chart label overlaps with the graph when labels are long
- Highchart specific width stack column bar graph
- Manage multiple highchart charts in a single webpage
- World map paths data in react high charts
- drawing custom lines on highchart graph
- Background color for multiple Highchart panes, in Vue app
- knockoutJS dynamic chart with high charts
- change legend color high charts based on data
More Query from same tag
- How to import highchart-more into angular 4 project
- Interaction with multiple charts in a page
- How to plot line chart with series data in highcharts?
- highcharts.js how to make double donut charts in one raw?
- Getting numbers on Y-axis to show up as percentages with code from a Highcharts code generator tool?
- How to dynamically draw a separator on a pie chart
- HighCharts HIOptions.colors must be [string]?
- Add design to plotLabel Highcharts
- Highcharts: how to maintain the same order of category labels when bar chart changes to column chart
- Highcharts - Pie Chart - link in tooltip
- how to get last value shown yAxis highcharts
- Changing month names of a highchart plot
- Can't get drilldown module to work in highcharts in typescript
- How can I do a dual axis using highcharter library?
- HighStock HighCharts Setting Flag on Click Event
- HighStocks needs to display categories instead of date
- Tile layout for highcharts legend items
- How we configure highchart x axis start from first tick?
- Highcharts bubbles incorrect initial size, changes on resize
- How can show multiple data on hover with highmaps?
- Highcharts export only renders one quarter of the image
- Highcharts: how to assign different colours to a spline depending on positive or negative slope?
- How to align the labels of sankey diagram?
- Customize Stacked column chart in highChart
- How to style two different legends in HighCharts
- Last label on xaxis disappears when resize
- How to make highchart from view table in Yii2?
- HighCharts: draw multiple segments in a single serie?
- Using HighchartsPHP library in CakePHP
- Highchart, SQL and Laravel