在Highchart脚本中使用空白图形问题 [英] Issue having blank graphic in Highchart script
问题描述
我遵循了 http://www.highcharts.com/demo/column-基本/天空和问题是我从我的控制器到我的Highchart图形的值显示为空白(没有显示我的值)
这里我的表< a href =http://sqlfiddle.com/#!2/b7347/5 =nofollow> http://sqlfiddle.com/#!2/b7347/5 我用在我的控制器
| policies |
ID POLICY_NUM DATE_INI CATEGORY_ID
1 1234 2013-01-10 1
2 5678 2013-01-10 2
3 3444 2013-02-10 1
4 4577 2013-02-10 2
|类别|
ID姓名
1人生
2车辆
这是我的控制器
def报表
@jan_life = Policy.find_by_sql(select count(*)as total来自政策内部加入类别ON categories.id = category_id WHere category_id = 1 AND date_ini BETWEEN'2013-01-01'AND'2013-01-31')
@jan_vehi = Policy.find_by_sql( 选择计数(*)作为政策总数内部加入类别ON categories.id = category_id WHere category_id = 2 AND date_ini BETWEEN'2013-01-01'AND'2013-01-31')
@feb_life = Policy.find_by_sql(select count(*)as policy total from policies内部加入类别ON categories.id = category_id WHere category_id = 1 AND date_ini BETWEEN'2013-02-01'AND'2013-02-28' )
@feb_vehi = Policy.find_by_sql(select count(*)as policy total from policies内部加入类别ON categories.id = category_id WHere category_id = 2 AND date_ini BETWEEN'2013-02-01'AN D'2013-02-28')
结束
这里是我的观点
#####禁用原型#####
#####显示高图表代码####
< script src =https://ajax.googleapis.com/ajax/libs/jquery/1.10。 2 / jquery.min.js>< /脚本>
#####我的控制器的值实际上正在工作####
<%= @jan_life [0] .try(:total)%> #it根据info
<%= @jan_vehi [0] .try(:total)%>显示1个值。 #it根据info
<%= @feb_life [0] .try(:total)%>显示1个值。 #it根据info
<%= @feb_vehi [0] .try(:total)%>显示1个值。 #it根据信息显示1个值
####此代码为HighChart图片####
< script src =http://code.highcharts.com/modules/exporting.js>< / script>
< div id =containerstyle =min-width:310px; height:400px; margin:0 auto>< / div>
< script type =text / javascript>
$($ {
$(b $ b $'$'$'$'$'$'$'$'$'$'$'$' b标题:{
text:'月平均降雨量'
},
副标题:{
text:'来源:WorldClimate.com'
},
xAxis:{
类别:[
'Jan',
'Feb'
]
},
yAxis:{
min: 0,
title:{
text:'Rainfall(mm)'
}
},
tooltip:{
headerFormat:'< span style =font-size:10px> {point.key}< / span>< table>,
pointFormat:'< tr>< td style =color:{series.color} ; padding:0> {series.name}:< / td>'+
'< td style =padding:0>< b> {point.y:.1f} mm< ; / b>< / TD>< / TR& '
footerFormat:'< / table>',
shared:true,
useHTML:true
},
plotOptions:{
专栏:{
pointPadding:0.0,
borderWidth:0
}
},
系列:[{
name:'Life',
数据:@jan_life [0] .try(:total)%>,
},{
名称:'车辆',
数据:@feb_life [0] .try(:total)%>
}]
});
});
< / script>
我做错了什么?显示为空白似乎不是传递参数
以下是我应该拥有的高级代码视图 http://jsfiddle.net/ajEF2/ 。
但我不想写这个值,我想用来自我的控制器的值显示在我的报告图像中
请有人可以帮我解决这个问题吗?
我会非常感谢帮助
夫妇的事情:
<1>您是否在数据分配中缺少<%=
:
系列:[{
name:'Life',
data:**<%= ** @jan_life [0] .try(:total)%>,
$,b $ b名称:'车辆',
数据:**<%= ** @feb_life [0] .try(:total)%>
]]
2。) done rails,但不会<%= @feb_life [0] .try(:total)%>
产生单一值?您最终会得到:
系列:[{
name:'Life',
data :1
},{
名称:'车辆',
数据:1
}]
data属性必须是一个数组。尝试:
系列:[{
name:'Life',
data:[<% = @ jan_life [0] .try(:total)%>] //注意括号。
},{
名称:'车辆',
数据:[<%= @ feb_life [0] .try(:total)%>]
}]
I followed steps from http://www.highcharts.com/demo/column-basic/skies and the issue is that my values from my controller to my Highchart graphic is showing blank ( is not showing my value)
Here my tables http://sqlfiddle.com/#!2/b7347/5 that i use in my controller
|policies|
ID POLICY_NUM DATE_INI CATEGORY_ID
1 1234 2013-01-10 1
2 5678 2013-01-10 2
3 3444 2013-02-10 1
4 4577 2013-02-10 2
|categories|
ID NAME
1 Life
2 Vehicles
Here is my controller
def report
@jan_life =Policy.find_by_sql("select count(*) as total from policies Inner join categories ON categories.id =category_id WHere category_id = 1 AND date_ini BETWEEN '2013-01-01' AND '2013-01-31'")
@jan_vehi =Policy.find_by_sql("select count(*) as total from policies Inner join categories ON categories.id =category_id WHere category_id = 2 AND date_ini BETWEEN '2013-01-01' AND '2013-01-31'")
@feb_life =Policy.find_by_sql("select count(*) as total from policies Inner join categories ON categories.id =category_id WHere category_id = 1 AND date_ini BETWEEN '2013-02-01' AND '2013-02-28'")
@feb_vehi =Policy.find_by_sql("select count(*) as total from policies Inner join categories ON categories.id =category_id WHere category_id = 2 AND date_ini BETWEEN '2013-02-01' AND '2013-02-28'")
end
Here is my view
##### To Disable prototype #####
<script type="text/javascript">Array.prototype.reduce = undefined;</script>
##### To show High Chart Code ####
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
##### Values from my controller , actually is working ####
<%= @jan_life[0].try(:total) %> #it shows 1 value according with the info
<%= @jan_vehi[0].try(:total) %> #it shows 1 value according with the info
<%= @feb_life[0].try(:total) %> #it shows 1 value according with the info
<%= @feb_vehi[0].try(:total) %> #it shows 1 value according with the info
#### This code is HighChart image ####
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: 'Monthly Average Rainfall'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
categories: [
'Jan',
'Feb'
]
},
yAxis: {
min: 0,
title: {
text: 'Rainfall (mm)'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.0,
borderWidth: 0
}
},
series: [{
name: 'Life',
data: @jan_life[0].try(:total) %>,
} , {
name: 'Vehicles',
data: @feb_life[0].try(:total) %>
}]
});
});
</script>
What I'm doing wrong? is showing blank seems that is not passing params
Here is the highchart code view that I should have http://jsfiddle.net/ajEF2/ .
But I don't want to write the value ,I want use values from my controller to show in my report image
Please somebody can help me with this?
I will really appreciate help
Couple things:
1.) Aren't you missing the <%=
in your data assignment:
series: [{
name: 'Life',
data: **<%=** @jan_life[0].try(:total) %>,
} , {
name: 'Vehicles',
data: **<%=** @feb_life[0].try(:total) %>
}]
2.) It's been a while since I've done rails but won't <%= @feb_life[0].try(:total) %>
produce a single value? You'll end up with:
series: [{
name: 'Life',
data: 1
} , {
name: 'Vehicles',
data: 1
}]
The data property must be an array. Try:
series: [{
name: 'Life',
data: [<%=@jan_life[0].try(:total) %>] //note the brackets.
} , {
name: 'Vehicles',
data: [<%=@feb_life[0].try(:total) %>]
}]
这篇关于在Highchart脚本中使用空白图形问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!