【发布时间】:2012-06-25 21:37:43
【问题描述】:
我正在尝试在 ActiveAdmin 的仪表板中包含一个包含部分内容的部分。该部分出现,但它是空白的 - 如何使部分出现?我想显示一个 Highcharts 图表。
这是我的代码:
dashboards.rb:
section "Business Summary", do
div do
render 'graph'
end
end
_graph.html.erb(位于app/views/admin/dashboard):
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'column'
},
xAxis: {
categories: ['Automotive', 'Agency', 'Contractor', 'Country Club', 'Other']
},
yAxis: {
min: 0,
title: {
text: 'Business Summary'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: 100,
verticalAlign: 'top',
y: 0,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function() {
return '<b>' + this.x + '</b><br/>' + this.series.name + ': ' + this.y + '<br/>' + 'Total: ' + this.point.stackTotal;
}
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: [{
name: 'Mobile',
data: [5, 3, 4, 27, 2]},
{
name: 'Foursquare',
data: [2, 2, 3, 2, 1]},
{
name: 'Facebook',
data: [3, 4, 4, 2, 5]},
{
name: 'Yelp',
data: [3, 4, 4, 2, 5]},
{
name: 'Google',
data: [3, 4, 4, 2, 5]}]
});
});
});
</script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
【问题讨论】:
-
您是否尝试为部分指定完整路径名(即
render 'admin/dashboard/graph')? -
我刚试过,现在我得到这个错误 =
Missing partial render admin/dashboard/graph with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :arb, :coffee]} -
我可以得到一个虚拟的部分工作,所以我认为问题在于实际的部分代码......
标签: ruby-on-rails highcharts partial-views activeadmin