私はangularjsとamchartの両方を初めて使用しています。私がしようとしているのは、コントローラ(asp.netコア)からjsonでいくつかのデータを送信しているということです。データは、amarChartを使用して基本チャートを作成すると仮定している角度コントローラに送られます。グラフの値フィールドに未定義のオブジェクトが表示されているAngularjを持つチャンス
グラフのカテゴリフィールドには、国名の代わりに「未定義」と表示されています。コードが正常に実行されているようだが、私はエラーを見つけることができません。以下は私のコードです。
以下は、asp.netコアで書かれたデータを送信するクラスとコントローラです。
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);
}
次は私のAngularjsコントローラです。
var myApp = angular.module( "main"、[]);
myApp.controller( "myController"、関数($の範囲、$ 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');
});
})。
次のビューコード(MVC asp.netコア)。
@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
OMG私は文字通り驚いています!これは間違いでした!いずれかの方法 !大変ありがとう! –