json - 如何为此 highchart 加载 JSON - django 应用程序
问题描述
我正在做 django 项目
我想做一个highchart依赖轮但我不知道为什么图表没有显示,你会在下面看到我的代码,在我的dependencywheel.html中我已经{%load static%}
在顶部,
<script>
Highcharts.chart('container', {
title: {
text: 'Highcharts Dependency Wheel'
},
accessibility: {
point: {
valueDescriptionFormat: '{index}. From {point.exped} to {point.destin}: {point.count}.'
}
},
series: [{
keys: ['exped', 'destin', 'count'],
data: '{%url "data"%}',
type: 'dependencywheel',
name: 'Dependency wheel series',
dataLabels: {
color: '#333',
textPath: {
enabled: true,
attributes: {
dy: 5
}
},
distance: 10
},
size: '95%'
}]
});
</script>
这是我的意见.py
@login_required
def depend(request):
return render(request,'dependWheel.html',{})
def jsonDepend(request):
dataset = mail_item_countries_depend.objects.all().values_list('exped','destin','count')
data = list(dataset)
return JsonResponse(data, safe=False)
图表未显示,如何加载我的数据
解决方案
这就是答案:
<script type="text/javascript">
$(function(){
$.getJSON('data',function(data){
Highcharts.chart('container', {
title: {
text: 'Highcharts Dependency Wheel'
},
accessibility: {
point: {
valueDescriptionFormat: '{index}. From {point.from} to {point.to}: {point.weight}.'
}
},
series: [{
keys: ['from', 'to', 'weight'],
data:data,
type: 'dependencywheel',
name: 'Dependency wheel series',
dataLabels: {
color: '#333',
textPath: {
enabled: true,
attributes: {
dy: 5
}
},
distance: 10
},
size: '95%'
}]
});
});
});
</script>
推荐阅读
- java - Can't find the "Create Manifest" button in the Artifacts dialog
- ios - 从 uiactivityviewcontroller iOS 中删除第三方应用程序
- google-bigquery - 如何从 GCS 中的文件中自动检测架构并加载到 BigQuery?
- azure - Azure CDN:规则引擎中的通配符
- dart - 是否可以无延迟地使用超时?
- sql - 字符串拆分字符串与多列相同的分隔符
- javascript - 突出显示 html 原始文本中的特定文本
- typescript - Reflect.Decorate 不是函数
- python - 美丽的汤提取物循环
- java - Java Reactor中阻塞调用后如何重新抛出错误?