问题
Got a problem with highcharts. I have series with dated data (debit, month) and want to graph it. I can graph data (debit only), but when i want to add datetimes, there are 2 problems :
- x_axis data are bad displayed (00:00:00.00)(00:00:00.00), expecting month-year (08/2012)
- Tooltip told me "Invalid date"
def index
@ops = getConstantOps()
@js_data = []
@ops.each { |f|
tmp = [f.date_operation,f.debit]
@js_data.push(tmp)
}
@h = LazyHighCharts::HighChart.new('graph') do |f|
f.options[:chart][:defaultSeriesType] = "area"
f.x_axis({:type =>'datetime'} )
f.series( :name=>'Ops', :data=>@js_data)
end
Ruby debug(@js_data) says
{--- !ruby/object:LazyHighCharts::HighChart
collection_filter:
data:
- :name: Ops
:data:
- - 2010-07-08
- 387.0
- - 2010-08-09
- 476.0
- - 2010-09-08
- 443.0}
So I need not to use "pointInterval" and "pointStart" because for some months I don't have any Ops. That's why I need a 2-dimension array as data param. I'm testing ruby/highcharts combination to build a company app, but quite a new on theese two tools.
Any ideas on how to make this work?
EDIT 11/11/2012 : After a fiw hours of work, it works! I've done a helper to do the crap cast.
Solution :
def getTimestamp(dateTime)
return (DateTime.parse(dateTime.year.to_s + '-' + dateTime.month.to_s + '-01')).to_i * 1000
end
It look dirty for me (2 casts, dans hard day param). But didn't find cleaner way. If you have one, plz suggest ;).
来源:https://stackoverflow.com/questions/13332291/lazyhighchart-and-dated-data