来自 mySql 的 amCharts json 数据 - 图表未显示
amCharts json data from mySql - Chart not displaying
无法使用数据库数据显示饼图。我的 json 好看吗?
样本Json
[{"id":1,"sport":"football","score":138.10,"entry":3.00,"winnings":8.00},{"id":2,"sport":"basketball","score":120.00,"entry":10.00,"winnings":20.00}]
我知道图表正在连接到数据集,因为我得到了一个以 NaN 作为标签的彩色块,一个块代表我数据库中的每一行。参见 image。 "entry" 是 Db 中的一个浮点数,我已经将它与另一个在 Db 中是 Int 的字段交换了,因为我认为该浮点数作为非数字返回,但看起来不是案.
<script type="text/javascript">
AmCharts.makeChart("piechartdiv", {
"type": "pie",
"dataLoader": {
"url": "http://siteaddress.com/api/entries",
"format": "json",
"showErrors": "true"
},
"titlefield": "sport",
"valuefield": "entry",
"balloontext": "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>",
"legend": {
"align": "center",
"markertype": "circle"
}
});
</script>
<div id="piechartwrapper">
<div id="piechartdiv" style="width: 100%" class="col-md-6 col-md-offset-0"></div>
</div>
您的字段设置不正确 - 它们区分大小写。 titleField
、valueField
、balloonText
和 markerType
是驼峰式大小写。您的配置全部为小写。
更新了以下代码:
AmCharts.makeChart("piechartdiv", {
"type": "pie",
"dataLoader": {
"url": "http://siteaddress.com/api/entries",
"format": "json",
"showErrors": "true"
},
"titleField": "sport",
"valueField": "entry",
"balloonText": "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>",
"legend": {
"align": "center",
"markerType": "circle"
}
});
无法使用数据库数据显示饼图。我的 json 好看吗?
样本Json
[{"id":1,"sport":"football","score":138.10,"entry":3.00,"winnings":8.00},{"id":2,"sport":"basketball","score":120.00,"entry":10.00,"winnings":20.00}]
我知道图表正在连接到数据集,因为我得到了一个以 NaN 作为标签的彩色块,一个块代表我数据库中的每一行。参见 image。 "entry" 是 Db 中的一个浮点数,我已经将它与另一个在 Db 中是 Int 的字段交换了,因为我认为该浮点数作为非数字返回,但看起来不是案.
<script type="text/javascript">
AmCharts.makeChart("piechartdiv", {
"type": "pie",
"dataLoader": {
"url": "http://siteaddress.com/api/entries",
"format": "json",
"showErrors": "true"
},
"titlefield": "sport",
"valuefield": "entry",
"balloontext": "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>",
"legend": {
"align": "center",
"markertype": "circle"
}
});
</script>
<div id="piechartwrapper">
<div id="piechartdiv" style="width: 100%" class="col-md-6 col-md-offset-0"></div>
</div>
您的字段设置不正确 - 它们区分大小写。 titleField
、valueField
、balloonText
和 markerType
是驼峰式大小写。您的配置全部为小写。
更新了以下代码:
AmCharts.makeChart("piechartdiv", {
"type": "pie",
"dataLoader": {
"url": "http://siteaddress.com/api/entries",
"format": "json",
"showErrors": "true"
},
"titleField": "sport",
"valueField": "entry",
"balloonText": "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>",
"legend": {
"align": "center",
"markerType": "circle"
}
});