$(function () {
$('#container').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Test Progress'
},
xAxis: {
title: {
text: 'Date'
},
type: "datetime"
},
yAxis: {
title: {
text: 'Grade'
}
},
credits: { enabled: false },
series: [{
data: [[1331028000000, 5], [1331031600000, 6], [1331035200000, 4]]
}]
});
});
By following this thread, http://*.com/questions/9548326/what-format-does-the-highcharts-js-library-accept-for-dates
通过这个主题,http://*.com/questions/9548326/what-format-does-the-highcharts-js-library-accept-for-dates
it says that i can input the dates in the above way inside data but it shows time instead of date.
它说我可以在数据中以上述方式输入日期,但它显示时间而不是日期。
Also i tried the first method and still gives me time. How can i display dates?
我也尝试了第一种方法,仍然给我时间。我该如何显示日期?
Also i am trying to get the dates from records and display them there, in what format do i need to convert them to properly show them?
此外,我试图从记录中获取日期并在那里显示它们,我需要以什么格式将它们转换为正确显示它们?
1 个解决方案
#1
0
For those wondering here is the query i have come up with
对于那些想知道这里是我提出的查询
Test.where("user_id = ?", 25).order('created_at DESC').select(:grade,:created_at).map { |g| [ g.created_at.to_i * 1000, g.grade.to_i ] }.inspect
Test.where(“user_id =?”,25)。order('created_at DESC')。select(:grade,:created_at).map {| g | [g.created_at.to_i * 1000,g.grade.to_i]} .inspect
i wrapped this query in a method and called the method in view
我在一个方法中包装了这个查询,并在视图中调用了该方法
series: [{
data: <%= grades %>
}]
this creates this line of code
这会创建这一行代码
data: [[1454777030000, 25], [1454598308000, 50], [1454598191000, 75], [1454163373000, 100], [1454163332000, 100], [1454163177000, 100], [1454163000000, 0], [1454096412000, 50], [1454096220000, 50], [1454095875000, 0], [1454095853000, 50], [1454082249000, 22], [1454081128000, 100], [1453037445000, 100]]
数据:[[1454777030000,25],[1454598308000,50],[1454598191000,75],[1454163373000,100],[1454163332000,100],[1454163177000,100],[1454163000000,0],[1454096412000,50] ,[1454096220000,50],[1454095875000,0],[1454095853000,50],[1454082249000,22],[1454081128000,100],[1453037445000,100]]
which seems to work with highcharts
这似乎与highcharts一起使用
#1
0
For those wondering here is the query i have come up with
对于那些想知道这里是我提出的查询
Test.where("user_id = ?", 25).order('created_at DESC').select(:grade,:created_at).map { |g| [ g.created_at.to_i * 1000, g.grade.to_i ] }.inspect
Test.where(“user_id =?”,25)。order('created_at DESC')。select(:grade,:created_at).map {| g | [g.created_at.to_i * 1000,g.grade.to_i]} .inspect
i wrapped this query in a method and called the method in view
我在一个方法中包装了这个查询,并在视图中调用了该方法
series: [{
data: <%= grades %>
}]
this creates this line of code
这会创建这一行代码
data: [[1454777030000, 25], [1454598308000, 50], [1454598191000, 75], [1454163373000, 100], [1454163332000, 100], [1454163177000, 100], [1454163000000, 0], [1454096412000, 50], [1454096220000, 50], [1454095875000, 0], [1454095853000, 50], [1454082249000, 22], [1454081128000, 100], [1453037445000, 100]]
数据:[[1454777030000,25],[1454598308000,50],[1454598191000,75],[1454163373000,100],[1454163332000,100],[1454163177000,100],[1454163000000,0],[1454096412000,50] ,[1454096220000,50],[1454095875000,0],[1454095853000,50],[1454082249000,22],[1454081128000,100],[1453037445000,100]]
which seems to work with highcharts
这似乎与highcharts一起使用