我是angularjs和amcharts的新手 . 我想要做的是我从控制器(asp.net核心)发送json中的一些数据 . 数据被发送到angularjs控制器,然后假设使用amCharts创建基本图表 .
在图表的类别字段中,我将编写“未定义”而不是国家/地区的名称 . 代码似乎运行正常,但我只是找不到错误 . 以下是我的代码 .
The following is the class and controller from which i am sending the data written in asp.net core.
public class tempCountry
{
public string Country { get; set; }
public int Visits { get; set; }
}
[HttpGet]
public IActionResult Charts_Json()
{
List<tempCountry> tempCountry = new List<chartController.tempCountry>();
tempCountry tObj = new tempCountry();
tObj.Country = "Pakistan";
tObj.Visits = 500;
tempCountry.Add(tObj);
tObj = new tempCountry();
tObj.Country = "Japan";
tObj.Visits = 1000;
tempCountry.Add(tObj);
tObj = new tempCountry();
tObj.Country = "India";
tObj.Visits = 3000;
tempCountry.Add(tObj);
tObj = new tempCountry();
tObj.Country = "Austrailia";
tObj.Visits = 4000;
tempCountry.Add(tObj);
return Json(tempCountry);
}
The following is my Angularjs controller.
var myApp = angular.module(“main”,[]);
myApp.controller(“myController”,function($ scope,$ http){
$http({
method: "GET",
url: "/chart/charts_json"
}).then(function mySuccess(response) {
chartdata = response.data;
var chart = new AmCharts.AmSerialChart();
chart.dataProvider = response.data;
chart.categoryFeild = "Country";
var graph = new AmCharts.AmGraph();
graph.valueField = "Visits";
chart.addGraph(graph);
chart.write('chartdiv');
});
});
The following the view code (MVC asp.net core).
@section scripts {
<script src="~/js/amcharts/amcharts.js"></script>
<script src="~/js/amcharts/serial.js"></script>
<script src="~/lib/angular/angular.js"></script>
<script src="~/js/mainApp.js"></script>
}
<p>this is the chart view page</p>
<body>
<div ng-app="main">
<div ng-controller="myController">
</div>
</div>
<div id="chartdiv" style="width:640px; height: 480px;">
</div>
</body>
以下是我得到的输出截图enter image description here
1 回答
categoryFeild
不是有效的amCharts属性 .如果这就是你拼写属性的字面意思,你可以在amCharts网站上编辑column chart并使用categoryFeild重现你生成的相同
undefined
列名 .相反,请尝试用 categoryField 替换
categoryFeild
.https://docs.amcharts.com/3/javascriptstockchart/AmSerialChart#categoryField