0

更新:似乎所有问题都通过在 html 文件本身中包含 bootstrap.min.js 解决了(即使 bootstrap 文件是从布局扩展的,它也必须在其他依赖脚本之后包含,因为它的组件不是' t 被他们访问)。除非其他人可以这样做,否则我会尽可能地发布作为答案(我可能不像你那样理解这个问题)。

我正在尝试使用 Web2py 来测试一个简单的MetricsGraphics 示例,但浏览器中没有加载图表。

阻止图表显示的当前错误:

TypeError: $(args.target+' h2.chart_title').popover is not a function. (In '$(args.target+' h2.chart_title').popover', '$(args.target+' h2.chart_title').popover' is undefined)

错误发生在metricsgraphics.min.js

HTML 文件:

{{extend 'layout.html'}}
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script src="{{=URL('static','js/d3/d3.min.js')}}"></script>

<link href="{{=URL('static','js/metric-graphics/css/metricsgraphics.css')}}" rel='stylesheet' type="text/css">
<script src="{{=URL('static','js/metric-graphics/js/metricsgraphics.min.js')}}"></script>


<h3>Graph</h3>

<div class="result text-center col-xs-5">

<script>
 data_graphic({
  title: "UFO Sightings",
  description: "Yearly UFO sightings from 1945 to 2010.",
  data: [{'year':1964, 'sightings':6}] // JSON.parse({{=sample}}), // also tried as JSON.parse([{"year":1945, "sightings":"6"}])
  markers: [{'year': 1964, 'label': '"The Creeping Terror" released'}],
  width: 600,
  height: 250,
  target: ".result",
  x_accessor: "year",
  y_accessor: "sightings",
});
</script>
{{#=BEAUTIFY(response._vars)}}

Python控制器功能:

def chart_view():
    '''This will show the graph for a feed (axes)'''

    # sample = [{"year": "1945", "count": 6}, {"year": "1950", "sightings": 35}, {"year": "1964", "sightings": 6}]

    return dict()
4

1 回答 1

1

要将 Python 对象写入视图,必须在其前面加上等号:

{{=sample}}

可能还有其他错误,因为不清楚您是如何获得sample该视图的。

于 2017-03-01T13:38:15.503 回答