使用插件数据dataLoader,amcharts加载数据(Uncaught TypeError:无法读取属性' toString' of undefined)

时间:2015-10-26 16:45:32

标签: javascript asp.net-mvc amcharts

我尝试使用dataLoader加载数据来构建图表(Amcharts) 并且为了我从控制器(APS.NET MVC Web应用程序)调用返回JSON数据的方法,数据包含日期,我认为这导致了问题

这是返回JSON的方法:

 [HttpGet]
    public JsonResult DataStatSum()
    {
        string dossier = Session["Dossier"].ToString();  
        string societe = Session["Societe"].ToString(); 
        int userId = Int32.Parse(Session["USER_ID"].ToString());

        List<Report_DrillDownSum_Result> l = db.Report_DrillDownSum(dossier,societe, 62, 353, 354).ToList();
        var jsonn = new JavaScriptSerializer().Serialize(l);
        var json = Newtonsoft.Json.JsonConvert.SerializeObject(l);
        return Json(json, JsonRequestBehavior.AllowGet);

    }

这是javascript代码(图表配置):

 <script src="~/js/jquery-1.11.0.min.js"></script>
<script src="~/js/amchratsV3.17.2/amcharts/amcharts.js"></script>
<script src="~/js/amchratsV3.17.2/amcharts/serial.js"></script>
<script src="~/js/amchratsV3.17.2/amcharts/plugins/dataloader/dataloader.js"></script>
<script src="~/js/amchratsV3.17.2/amcharts/themes/light.js"></script>
@*<script src="~/js/date.format.js"></script>*@

<script type="text/javascript">
    AmCharts.makeChart("chartdiv",
       {
           "type": "serial",
           "dataLoader":
           {
               "url": "/ChartStat/DataStatSum",
               "format": "json"
           },
           "categoryField": "JourD",
           "dataDateFormat": "YYYY-MM-DD",
           "angle": 30,
           "depth3D": 30,
           "startDuration": 1,
           "fontSize": 14,
           "handDrawn": true,
           "handDrawScatter": 4,
           "theme": "light",
           "categoryAxis": {
               "gridPosition": "start",
               "parseDates": true
           },
           "trendLines": [],
           "graphs": [
               {
                   "balloonText": "[[title]] : [[value]] km",
                   "fillAlphas": 1,
                   "id": "AmGraph-1",
                   "title": "Athlete 1",
                   "type": "column",
                   "valueField": "ValDim1"
               },
               {
                   "balloonText": "[[title]] : [[value]] km",
                   "fillAlphas": 1,
                   "id": "AmGraph-2",
                   "title": "Athlete 2",
                   "type": "column",
                   "valueField": "ValDim2"
               }
           ],
           "guides": [],
           "valueAxes": [
               {
                   "id": "ValueAxis-1",
                   //   "title": "Axis title"
               }
           ],
           "allLabels": [],
           "balloon": {},
           "legend": {
               "useGraphSettings": true
           },
           "titles": [
               {
                   "id": "Title-1",
                   "size": 15,
                   "text": "Distance parcourue (km)"
               }
           ],

       })

实际上,当我输入&#34; dataDateFormat&#34;:&#34; YYYY-MM-DD&#34;

JSON数据如下所示:

"[{\"JourD\":\"2015-09-01\",\"ValDim1\":17126.0,\"ValDim2\":18080.0},{\"JourD\":\"2015-09-08\",\"ValDim1\":16960.0,\"ValDim2\":18000.0},{\"JourD\":\"2015-09-15\",\"ValDim1\":17880.0,\"ValDim2\":18075.0}]" 

当我尝试显示图表时,我在谷歌Chrome控制台中收到此错误: 未捕获的TypeError:无法读取属性&#39; toString&#39;未定义的。

更改我的方法来解决这个问题,因为我不需要将对象转换为JSON字符串

[HttpGet]
public JsonResult DataStatSum()
{
    string dossier = Session["Dossier"].ToString();  
    string societe = Session["Societe"].ToString(); 
    int userId = Int32.Parse(Session["USER_ID"].ToString());

    List<Report_DrillDownSum_Result> l = db.Report_DrillDownSum(dossier,societe, 62, 353, 354).ToList();
     return Json(l, JsonRequestBehavior.AllowGet);

}

0 个答案:

没有答案