2016-07-28 50 views
1

我是angularjs和amcharts的新手。我想要做的是我从控制器(asp.net核心)发送json中的一些数据。数据发送到angularjs控制器,然后假设使用amCharts创建基本图表。amCharts与Angularjs在图表的值字段中显示未定义的对象

在图表的类别字段中,我得到了“Undefined”而不是国家的名称。该代码似乎运行良好,但我无法找到该错误。以下是我的代码。

以下是我从中发送用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

回答

0

chart.category 费尔德 = “国家” 的屏幕截图;

categoryFeild不是有效的amCharts属性。

如果是从字面上你是如何拼写的属性, 您可以编辑amCharts网站上column chart和使用类别费尔德重现您所生成相同undefined列名。

请改为categoryFeild替换categoryField

https://docs.amcharts.com/3/javascriptstockchart/AmSerialChart#categoryField

+0

OMG我是从字面上惊讶!这是错误的!无论如何 !非常感谢! –

相关问题