gpt4 book ai didi

javascript - 从 Amcharts 中的 getJSON 转换时,ajax 调用不起作用

转载 作者:行者123 更新时间:2023-11-28 04:54:04 25 4
gpt4 key购买 nike

这是javascript文件中的ajax调用方法,用于在Amcharts中绘制条形图。

bar.js

plot_graph();

function plot_graph(){

$.ajax({


url:back+"/cool?day=30",

type: "GET",
dataformat: "JSON",



success: function(data){
alert("succes while plotting down graph");

var amc=AmCharts.makeChart("plot",
{
"type": "serial",

"dataSets": [{
"dataProvider": data,
"categoryField": "time"
}],
"categoryField": "name",
"startDuration": 1,
"categoryAxis": {
"gridPosition": "start"
},
"trendLines": [],
"graphs": [
{
"balloonText": "[[title]] of [[category]]:[[value]]",
"fillAlphas": 0.8,
"lineAlpha": 0.2,
"id": "AmGraph-1",
"title": "Bar Graph",
"type": "column",
"valueField": "tips",
"color":"#6fdc6f"
},
{
"balloonText": "[[title]] of [[category]]:[[value]] k",
"fillAlphas": 1,
"id": "AmGraph-2",
"title": "Distance",
"type": "column",
"valueField": "mile"
}
],
"guides": [],
"valueAxes": [
{
"id": "ValueAxis-1",
"title": "Milage",
"gridColor": "#FFFFFF",
"gridAlpha": 0.2

}
],
"gridAboveGraphs": true,
"allLabels": [],
"balloon": {},
"legend": {
"enabled": true,
"useGraphSettings": true
},
"titles": [
{
"id": "Title-1",
"size": 15,
"text": " Cool"
}
]

});

},
error:function(){

alert("error while plotting down graph");

}
});

}

但是当我访问 webservice api 时,它会显示数据,并且出现警告框,并显示“绘制图表时成功”。但绘图并未绘制。如有任何帮助,我们将不胜感激。

最佳答案

dataSets 是股票图表属性,而不是系列图表属性(请注意您的图表类型)。您需要设置 dataProvider 并在配置的顶层设置 categoryField:

var amc = AmCharts.makeChart("plot", {
// ...
"dataProvider": data,
"categoryField": "time",
// ..
});

请注意,只允许有一个categoryField,而不是两个。

关于javascript - 从 Amcharts 中的 getJSON 转换时,ajax 调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42688583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com